• Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting IO Exception: file name,directory name or label name syntax incorrect at createNewFile().

 
SaiManasa Dasari
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

My requirement is creating new files with timestamp in the newly created folder.the files are creating fine in ubuntu machine.but getting IO Exception : file name,directory name or label name syntax incorrect at createNewFile() in windows machine.In windows the folder is creating with readonly permission.I have given write permission to that folder with the help of FilePermission class.but still i am getting same exception.I need solution in jdk1.5 version.not in 1.6 version.

Here is my code.Please help me in this.
String fs="/";
File localDir = new File("c:/programfiles"+fs+"myfile");
logFile = new File(localDir.getAbsolutePath()+ fs +"logs");
java.util.Date date = new Date();
logFile.mkdir();
new FilePermission(logFile.getAbsolutePath(),"write");
File logfile = new File(logFile.getAbsolutePath(),"log"+date.toString()+".txt");
logfile.createNewFile();

Thanks in advance.
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First check what is the format of String returned by toString() method of Date instance. If you check the API you can see that the result contains colon ':', which is not allowed as file name under Windows.

Furthermore, if you create more than one directory (or hierarchy of (sub)directories) you should invoke mkdirs() method.

I must say that I really don't like naming two variables logFile and logfile, I'm sure you'll make a mistake with it later on.
 
SaiManasa Dasari
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks kemal.After replacing : in datesting its working fine.thanks for your help.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!