Java 實(shí)例 - 讀取文件內(nèi)容
以下實(shí)例演示了使用 readLine() 方法來讀取文件 test.log 內(nèi)容,其中 test.log 文件內(nèi)容為:
w3cschool在線教程 www.o2fo.com
java 代碼如下:
/* author by w3cschool.cn Main.java */ import java.io.*; public class Main { public static void main(String[] args) { try { BufferedReader in = new BufferedReader (new FileReader("test.log")); String str; while ((str = in.readLine()) != null) { System.out.println(str); } System.out.println(str); } catch (IOException e) { } } }
以上代碼運(yùn)行輸出結(jié)果為:
優(yōu)聚教程 www.o2fo.com null
更多建議: