在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");//正确
在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");//正确