日期:2014-05-20 浏览次数:20930 次
package com.yaxing.io; import java.io.FileReader; import java.io.IOException; public class FileReaderDemo { /** * @param args */ public static void main(String[] args) { FileReader fw = null; try { fw = new FileReader("c:\\w.txt"); // int ch = 0; // while ((ch = fw.read()) != -1) { // System.out.println("读取:" + (char) ch); // } while ((fw.read()) != -1) { System.out.println("读取:" + (char)fw.read()); } } catch (IOException e) { e.printStackTrace(); } finally { if (fw != null) { try { fw.close(); } catch (IOException e) { e.printStackTrace(); } } } } }
读取:s 读取:c 读取:1 读取:3 读取:
asdcr1231
while ((fw.read()) != -1) { System.out.println("读取:" + (char)fw.read()); }