编程语言
首页 > 编程语言> > Java基础-FileReader文件字符输入流

Java基础-FileReader文件字符输入流

作者:互联网

package com.hspedu.io_;

import org.junit.Test;

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

public class TestFileReader {
    @Test
    public void readFile() {
        String filePath = "e:\\JavaIO\\FileReader\\test.txt";
        FileReader fileReader = null;
        int readData = 0;
        try {
            fileReader = new FileReader(filePath);
            while ((readData = fileReader.read()) != -1) {
                System.out.print((char) readData);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

        try {
            fileReader.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

 

标签:字符,Java,FileReader,readData,IOException,io,fileReader,import
来源: https://www.cnblogs.com/kenantongxue/p/16146341.html