Java中输入输出文件流操作
程序员文章站
2022-03-01 18:06:38
...
输入流(字符流):
public class ReadTreeUtil {
public static List<String> readFile(String path) throws IOException{
File file = new File(path);
InputStreamReader reader = null;
BufferedReader br = null;
List<String> resultList = new LinkedList<String>();
try {
reader = new InputStreamReader(new FileInputStream(file));
br = new BufferedReader(reader);
String line = "";
while ((line = br.readLine()) != null) {
resultList.add(line);
}
} catch (IOException e) {
e.printStackTrace();
} finally{
br.close();
reader.close();
}
return resultList;
}
}
上一篇: java 10进制和16进制的相互转换
下一篇: Java输入输出文件读取