What are possible reasons for java.io.IOException: “The filename, directory name, or volume label syntax is incorrect”

后端 未结 13 1488
一个人的身影
一个人的身影 2020-12-10 02:12

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

File targetFile = new File(targetPath + File.separator + filename);
...
targetFile.createNewFile();
file         


        
13条回答
  •  臣服心动
    2020-12-10 03:05

    Do you check that the targetPath is a directory, or just that something exists with that name? (I know you say the user can copy it from the operating system, but maybe they're typing something else).

    Does targetPath end with a File.separator already?

    (It would help if you could log and tell us what the value of targetPath and filename are on a failing case)

提交回复
热议问题