gpt4 book ai didi

Java 文件 mkdir 给出错误的结果

转载 作者:可可西里 更新时间:2023-11-01 10:58:02 24 4
gpt4 key购买 nike

所以我试图制作一个 map ,将一些文件存储在程序开始时制作的 dir 中。但是在 Windows 上仍然存在问题,因为目录永远不会创建。而且我找不到解决方案。相同的代码在 Unix 系统上运行完美,但在 Windows 系统上运行不佳。

protected String createScreenshotMap(){
this.dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
this.date = new Date();
String testMap = this.checkOS();
File fileMap = null;
boolean check;
try{
if(os.indexOf("win") >= 0){
fileMap = new File(testMap);
check = fileMap.canWrite();
System.out.println(check);
String path = "C:" + File.separator + "testRun" +
File.separator + this.date.toString();
fileMap = new File(path);
System.out.println(fileMap.getAbsolutePath());
}else{
fileMap = new File(testMap + this.date.toString() + "/");
}
check = fileMap.mkdir();
System.out.println(check);
}catch (Exception e){
e.printStackTrace();
}
return testMap;
}

如果我运行这段代码,我会得到以下输出

true
C:\testRun\Fri Apr 01 15:30:47 CEST 2016
false

我还检查了 testRun 是否存在,这对 java 来说没问题。我还检查了我是否可以写并且返回了 true,但它仍然不会在 testRun

中生成 dir

最佳答案

您不能使用 :(冒号)创建文件夹或文件名

详情:
对于Microsoft资源,以下字符是Windows保留的,不能用于创建文件夹或文件名:

< (less than)
> (greater than)
: (colon)
" (double quote)
/ (forward slash)
\ (backslash)
| (vertical bar or pipe)
? (question mark)
* (asterisk)

引用:

关于Java 文件 mkdir 给出错误的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36358053/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com