JAVA 读取本地文本文件

package sucai17;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

public class Yewu {
    public static void main(String[] args) throws Exception, IOException {
        String encoding = "UTF-8";
        File file = new File("C:\\Users\\admin\\Desktop\\1.txt");
        if (file.isFile() && file.exists()) { //判断文件是否存在
            InputStreamReader read = new InputStreamReader(
                    new FileInputStream(file), encoding);//考虑到编码格式
            BufferedReader bufferedReader = new BufferedReader(read);
            String lineTxt = null;
            while ((lineTxt = bufferedReader.readLine()) != null) {
                   System.out.println(lineTxt);         
             }       
            read.close();
        } else {
            System.out.println("找不到指定的文件");
        }

    }
}

你可能感兴趣的:(java,读取流)