如何使用 java 中的用户名创建子文件夹
How to create sub folder with username in java
我正在做一个小项目,有一个模块,即 KYC 更新,在这个模块中,我将 AadharCard、PAN 卡和其他文件保存在 Folder.So 我正在使用 java IO并尝试创建名称为 Document 的目录,我想创建一个带有用户名的子目录,并为创建唯一的也附加用户名,id concat.I 编写代码,但子目录没有创建。
我的密码是
String uploadPath = context.getRealPath("") + "assets" + File.separator + "Document" + File.separator
+ userPojo.getFirstName();
File file = new File(uploadPath);
try {
if (!file.exists()) {
file.mkdirs();
logger.debug("Make Dir");
}
我也试试这个
File file = new File(dir, userPojo.getUserName());
if (!file.exists()) {
file.mkdirs();
logger.debug("Make Dir");
}
我搜索并解决了我的问题problem.So如果有人遇到此类问题,我想提供解决方案
File file = new File(uploadPath);
File file2 = new File(uploadPath, dataPojo.getFirstName()));
if (!file.exists()) {
file.mkdirs();
logger.debug(file.getAbsolutePath());
}
if (!file2.exists()) {
file2.mkdirs();
logger.debug(file.getAbsolutePath());
}
我正在做一个小项目,有一个模块,即 KYC 更新,在这个模块中,我将 AadharCard、PAN 卡和其他文件保存在 Folder.So 我正在使用 java IO并尝试创建名称为 Document 的目录,我想创建一个带有用户名的子目录,并为创建唯一的也附加用户名,id concat.I 编写代码,但子目录没有创建。 我的密码是
String uploadPath = context.getRealPath("") + "assets" + File.separator + "Document" + File.separator
+ userPojo.getFirstName();
File file = new File(uploadPath);
try {
if (!file.exists()) {
file.mkdirs();
logger.debug("Make Dir");
}
我也试试这个
File file = new File(dir, userPojo.getUserName());
if (!file.exists()) {
file.mkdirs();
logger.debug("Make Dir");
}
我搜索并解决了我的问题problem.So如果有人遇到此类问题,我想提供解决方案
File file = new File(uploadPath);
File file2 = new File(uploadPath, dataPojo.getFirstName()));
if (!file.exists()) {
file.mkdirs();
logger.debug(file.getAbsolutePath());
}
if (!file2.exists()) {
file2.mkdirs();
logger.debug(file.getAbsolutePath());
}