日期:2014-05-20 浏览次数:20738 次
public static void main(String[] args) { Reader rf = null; int length = 0; char[] ch = null; StringBuffer sb = new StringBuffer(); try { rf = new FileReader("e:/aa.txt"); ch = new char[1024]; length = rf.read(ch); while (length != -1) { sb.append(ch); // ch = new char[1024]; length = rf.read(ch); } System.out.println(sb.toString()); } catch (Exception e) { e.printStackTrace(); } }
public class Test { public static void main(String[] args){ BufferedReader reader = null; try { reader = new BufferedReader(new FileReader("")); StringBuffer sb = new StringBuffer(); while(true){ String line = reader.readLine(); if(line == null){ break; } sb.append(line); } System.out.println(sb.toString()); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally{ if(reader != null){ try { reader.close(); } catch (IOException e) { e.printStackTrace(); } } } } }