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("文件读取错误!");
}
}
}

 

相关文章:

  • 2021-12-12
  • 2022-12-23
  • 2021-10-22
  • 2022-12-23
  • 2021-11-23
  • 2022-12-23
  • 2022-01-18
  • 2021-08-29
猜你喜欢
  • 2022-12-23
  • 2022-01-18
  • 2022-12-23
  • 2022-03-01
  • 2021-09-10
  • 2021-08-05
相关资源
相似解决方案