下面是我寫的壹個小例子,希望對妳有幫助!
File f =新文件(" d:\ \ io \ \ t . txt ");
FileReader fr = null
BufferedReader br = null
string buffer strb = new string buffer(" ");
String temp =
嘗試{
//輸入流
fr =新文件讀取器(f);
br =新buffered reader(fr);
//逐行讀取
while((temp=br.readLine())!=null){
strb . append(temp);
}
//期望的結果
system . out . println(strb);
} catch(異常e) {
e . printstacktrace();
}最後{
嘗試{
fr . close();
br . close();
} catch (IOException e) {
// TODO自動生成的catch塊
e . printstacktrace();
}
}