What are possible reasons for java.io.IOException: "The filename, directory name, or volume label sy

Posted by Turismo on Stack Overflow See other posts from Stack Overflow or by Turismo
Published on 2008-09-25T07:22:28Z Indexed on 2010/04/25 10:03 UTC
Read the original article Hit count: 348

Filed under:
|
|

I am trying to copy a file using the following code:

File targetFile = new File(targetPath + File.separator + filename);
...
targetFile.createNewFile();
fileInputStream = new FileInputStream(fileToCopy);
fileOutputStream = new FileOutputStream(targetFile);
byte[] buffer = new byte[64*1024];
int i = 0;
while((i = fileInputStream.read(buffer)) != -1) {
    fileOutputStream.write(buffer, 0, i);
}

For some users the targetFile.createNewFile results in this exception:

java.io.IOException: The filename, directory name, or volume label syntax is incorrect
    at java.io.WinNTFileSystem.createFileExclusively(Native Method)
    at java.io.File.createNewFile(File.java:850)

Filename and directory name seem to be correct. The directory targetPath is even checked for existence before the copy code is executed and the filename looks like this: AB_timestamp.xml

The user has write permissions to the targetPath and can copy the file without problems using the OS.

As I don't have access to a machine this happens on yet and can't reproduce the problem on my own machine I turn to you for hints on the reason for this exception.

© Stack Overflow or respective owner

Related posts about java

Related posts about exception