Java 實例 - 讀取文件內容
阿新 • • 發佈:2018-03-03
sta exception 蘋果 trace pri system throw AI pan
package IO; import java.io.*; public class resdContent { public static void main(String[] args) throws Exception { /** * 讀取文件內容 */ try { BufferedReader read = new BufferedReader(new FileReader("C:/hehe.txt"));//要保證文件夾下有這個文件 String str; while ((str = read.readLine())!=null) { System.out.println(str); } } catch (FileNotFoundException e) { e.printStackTrace(); } } }
輸出結果
你是我的小蘋果
怎麽愛你都不嫌多
紅紅的小臉溫暖我的心窩
Java 實例 - 讀取文件內容