執行結果
--------------------Configuration:
today is friday.註解text awt test
awt test註解
awt testtoday is friday.註解
Process completed. 編譯成功
1. filereader
import java.io.*;
public class te13 {
public static void main(String args[]) throws Exception {
FileReader fr = new FileReader("poi.txt");
BufferedReader br = new BufferedReader(fr);
String s; //= br.readLine();
//if(s != null) {
while((s= br.readLine())!=null){//每行字不是空字串
System.out.println(s);
if( s==null) br.close();
}
br.close();
fr.close();
} }
2.fileinputstream
import java.io.*;
public class te13_01
{
public static void main(String args[]) throws Exception {
FileInputStream fr = new FileInputStream("poi.txt");
byte b[]=new byte[256];
int s=fr.read(b);
if(true){
if(s!=-1)
System.out.println(new String(b,0,s));
if( s==-1)
fr.close();
}
}
}
- Mar 19 Tue 2013 00:09
java範例程式13 2種程式碼讀取中文文字檔(*.txt)
close
全站熱搜
留言列表
發表留言