我目前正在为文件管理服务器开发 RecycleBin 组件。当文档被删除时,所有版本都会从多个位置删除。发生这种情况时,所有文件夹路径都会被删除为重复字符串 dp_original_folder_paths。
我想在文件夹路径不存在时创建它。
这是我当前的代码。第一部分检查文件是否存在,如果不存在则创建它。第二部分显示文档被重新链接到文件夹。
for (int i = 0;
i < relationRecord.getValueCount("dp_original_folder_paths"); i++)
{
File f = new File(relationRecord.getRepeatingString(
"dp_original_folder_paths",
i));
if(!f.exists())
{
System.out.println("creating directory" + f);
f.mkdir();
}
// Link the document back to the original folders
for (int i = 0; i < relationRecord.getValueCount("dp_original_folder_paths")
i++)
{
document.link(
relationRecord.getRepeatingString("dp_original_folder_paths", i));
}
给出的输出是
正在创建目录:\EAM\sbotest
已创建目录
链接到/EAM/sbotest
DfPathNotFoundException::线程: http-bio-8080-exec-7;消息:[DM_API_E_EXIST]错误 或:“/EAM/sbotest 指定的文件夹不存在。”;错误代码:100;下一个:空
有谁知道为什么在第一个 println 中输出是\EAM\sbotest 而第二个输出\变成了//EAM/sbotest
感谢您的帮助。
最佳答案
从 Java 1.7 开始推荐使用
Files.createDirectories(new File("C:/dir1/dir2/dir3/").toPath());
关于Java 创建一个不存在的目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24682294/