sofeware construction lab中使用相对路径进行文件的读取
然而经历了若干次失败:
e.g.:
// String file1 = System.getProperty("\src\P1\txt\fileName");
// File file = new File(“file1”);
不得不选择另一种方法:
String root = System.getProperty(“user.dir”);
String filePath = root+File.separator+“P1”+File.separator+“txt”+ File.separator +fileName;
奇迹般地,不会抛出系统找不到文件了
原因:
1.使用System.getProperty(“user.dir”)获取当前程序运行的工作根目录
2.使用File.separator表示目录的分割符,此操作需要import java.io.File
参考网址:
https://blog.csdn.net/weixin_37602603/article/details/79548060
https://blog.csdn.net/u013555719/article/details/84104105