import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.Reader; public class FileReaderTest { /** * @param args */ public static void main(String[] args) { //建立 FileReader對象 Reader fr=null; StringBuffer sbf=null; try { fr = new FileReader("C:\\myDoc\\簡介.txt"); char ch[]=new char[1024]; //建立字符數組做爲中轉站 sbf=new StringBuffer(); int length=-1; //將字符讀入數組,循環讀取並追加字符 while ((length=fr.read(ch))!= -1) { sbf.append(ch); //追加到字符串 } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally{ try { if(fr!=null) fr.close(); } catch (IOException e) { e.printStackTrace(); } } System.out.println(sbf.toString()); } }