1.FileReader和FileInputStream的區別:spa
FileReader、FileWriter處理的是文本文件。code
FileInputStream/FileOutputStream是繼承InputStream/OutputStream的文件讀寫流,用於讀寫任何文件。對象
2.FileReader與BufferedReader的區別:blog
BufferedReader是一行行讀取。某些狀況下咱們只須要一行的數據,很方便。經過對象的readLine方法,能夠獲取一行文本。繼承
1)簡單用法:it
@Test public void testMyTest(){ try { Reader in = new FileReader("c://logFile.txt"); BufferedReader br = new BufferedReader(in); String line = br.readLine(); System.out.println(line); } catch (Exception e) { e.printStackTrace(); } }
運行結果:io
這是第一行的文本
2)複雜用法:class
@Test public void testMyTest(){ try { Reader in = new InputStreamReader(new FileInputStream(new File("c://logFile.txt")) , "GBK"); BufferedReader br = new BufferedReader(in); String line = br.readLine(); System.out.println(line); } catch (Exception e) { e.printStackTrace(); } }
結果同樣的test