1 import java.io.*;
2
3 public class ReadFile {
4 public static void main(String[] args) {
5
6 try {
7 File file = new File("E:\\JavaLog/logs/1.txt");
8 if (file.isFile() && file.exists()) {
9 //读取的时指定GBK编码格式,若中文出现乱码请尝试utf-8,window默认编码格式为GBK
10 BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "gbk"));
11 String lineTxt = null;
12 while ((lineTxt = br.readLine()) != null) {
13 System.out.println(lineTxt);
14 }
15 br.close();
16 } else {
17 System.out.println("文件不存在!");
18 }
19 } catch (Exception e) {
20 System.out.println("文件读取错误!");
21 }
22 }
23 }