标签:exists int catch window readline print reader ati except
import java.io.*; public class ReadFile { public static void main(String[] args) { try { File file = new File("E:\\JavaLog/logs/1.txt"); if (file.isFile() && file.exists()) { //读取的时指定GBK编码格式,若中文出现乱码请尝试utf-8,window默认编码格式为GBK BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "gbk")); String lineTxt = null; while ((lineTxt = br.readLine()) != null) { System.out.println(lineTxt); } br.close(); } else { System.out.println("文件不存在!"); } } catch (Exception e) { System.out.println("文件读取错误!"); } } }
原文:https://www.cnblogs.com/hechenhao/p/7773721.html
标签:exists int catch window readline print reader ati except
原文地址:https://www.cnblogs.com/peachh/p/12079976.html