java ->IO流_字符流
字符流 经过前面的学习,我们基本掌握的文件的读写操作,在操作过程中字节流可以操作所有数据,可是当我们操作的文件中有中文字符,并且需要对中文字符做出处理时怎么办呢? 字节流读取字符的问题 通过以下程序读取带有中文件的文件。 public class CharStreamDemo { public static void main(String[] args) throws IOException { //给文件中写中文 writeCNText (); //读取文件中的中文 readCNText (); } //读取中文 public static void readCNText() throws IOException { FileInputStream fis = new FileInputStream("c:\\cn.txt"); int ch = 0; while ((ch = fis.read())!=-1){ System. out .println(ch); } } //写中文 public static void writeCNText() throws IOException { FileOutputStream fos = new FileOutputStream("c:\\cn.txt"); fos.write("欢迎你".getBytes()); fos