比如在目录的文件夹下有个文件haha.txt,现在我通过计算知道string haha了,如何根据这个string来读取文件呢?
------解决方案--------------------
try {
FileReader fr = new FileReader(path); //path 为haha.txt的绝路径
BufferedReader br = new BufferedReader(fr);
/*逐行读取*/
String line = br.readLine();
while (line != null) {
System.out.println(line);
line = br.readLine();
}
br.close();
fr.close();
} catch (FileNotFoundException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}