获取文件上传路径报错:java.io.FileNotFoundException: (文件名、目录名或卷标语法不正确。)

在Windows中的文件路径格式为C:\Users\n\Desktop\MyText.txt
而在Java中的文件路径格式为 C:/Users/n/Desktop/MyText.txt
在java中使用前者则会报错,所以需要先将Windows中的文件路径转换为java中可识别的路径。

File myFile =new File("C:/Users/n/Desktop/MyText.txt");//正确

猜你喜欢

转载自blog.csdn.net/nsjlive/article/details/79546363