码迷,mamicode.com
首页 > 编程语言 > 详细

Java文件处理之FileReader可输出中文字符

时间:2019-10-09 15:23:00      阅读:115      评论:0      收藏:0      [点我收藏+]

标签:一个   while   style   print   int   har   dex   关闭   dem   

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class FileReaderDemo1 {
    public static void main(String[] args) throws IOException {
        //使用文件名创建流对象
        FileReader fr = new FileReader("a.txt");
        //定义一个变量,保存数据
        int c;
        while ((c=fr.read())!=-1){//每次读取一个字符
            System.out.println((char)c);//可输出中文字符
        }

//        char[] charBuff = new char[2]; 
//        while ((len=fr.read(charBuff))!=-1){//每次读取两个字符
//            System.out.println(new String(charBuff));
//
//        }

        fr.close();//关闭资源

    }
}

 

Java文件处理之FileReader可输出中文字符

标签:一个   while   style   print   int   har   dex   关闭   dem   

原文地址:https://www.cnblogs.com/theworld/p/11641937.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!