the java.io. * Import ; public class the ReadFile { public static void main (String [] args) { the try { File File = new new File ( " E: \\ JavaLog / logs / 1.txt " ); IF (file.isFile () && File.Exists ()) { // read the specified GBK encoding format, if Chinese distortion try utf-8, window default encoding format is GBK the BufferedReader br = new new the BufferedReader ( new new the InputStreamReader ( new new the FileInputStream (File ), " GBK " )); String lineTxt = null ; the while ((lineTxt = br.readLine ()) =! null ) { the System. OUT .println (lineTxt); } br.close (); } the else { . the System OUT .println ( " file does not exist! " ); } } the catch (Exception E) { . the System OUT .println ( " file read error! " ); } } }
Original: https: //www.cnblogs.com/hechenhao/p/7773721.html