view raw
Turismo Turismo - 9 months ago 88
Java Question

What are possible reasons for "The filename, directory name, or volume label syntax is incorrect"

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

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

For some users the
results in this exception: The filename, directory name, or volume label syntax is incorrect
at Method)

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

The user has write permissions to the
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.


Try this, as it takes more care of adjusting directory separator characters in the path between targetPath and filename:

File targetFile = new File(targetPath, filename);