Reputation: 483
So I'm trying to make a map to store some files in a dir
that is made at the beginning of the program. But on windows there is still a problem, because the directory is never made. And I can't find a solution. The same code works perfect on a Unix system but not on a Windows system.
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;
}
If I run this piece of code I get the following output
true
C:\testRun\Fri Apr 01 15:30:47 CEST 2016
false
I also checked I testRun
exist and that was OK for java. i also checked if I could write and that gave true back, but it will still not make a dir
in testRun
Upvotes: 1
Views: 144
Reputation: 33397
You can not create a folder or file name with :
(colon)
Details:
Regarding Microsoft resources, the following characters are reserved by Windows and can not be used to creating folder or filename:
< (less than)
> (greater than)
: (colon)
" (double quote)
/ (forward slash)
\ (backslash)
| (vertical bar or pipe)
? (question mark)
* (asterisk)
Reference:
Upvotes: 7