【发布时间】:2016-04-01 13:48:44
【问题描述】:
所以我正在尝试制作一个地图以将一些文件存储在程序开始时制作的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 来说没问题。我还检查了我是否可以写并且得到了真实的回复,但它仍然不会在testRun 中生成dir
【问题讨论】: