Reader字符流讀取文件內容---實例
阿新 • • 發佈:2018-06-03
ID TP 文件創建 cep 分享圖片 讀取 except ade 強制
import java.io.*; public class File4{ public static void main(String[] args)throws Exception{ //拋出異常,不處理 File f=new File("e:"+File.separator+"test.txt"); //選擇e:test.txt的文件創建對象 Reader input=new FileReader(f); char b[]=new char[(int)f.length()]; //定義一個char數組,數組大小由文件大小決定System.out.println("數組長度為:"+input.read(b)); //讀取數組內容到b數組中,並返回數組長度 System.out.println(new String(b)); //將char類型b數組強制轉換為String類型 input.close(); //關閉數據流 } }
Reader字符流讀取文件內容---實例