欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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;
	}
}