/** * Function: Java read content of TXT file * Step: 1: Get file Handle First * 2: Get file handle as input a byte stream, need to read this input stream * 3: Read to input stream, need to read generated byte stream * 4: one line The output of a row. ReadLine (). * Note: It is unusual to consider the situation * @param filePath
*String FilePath = "\\\\172.16.4.148\\transout\\mytxt.out";
*/ public void Readtxtfile (String filePath) { try {   ; String encoding= "GBK"; file File=new file (FilePath); nbsp if (File.isfile () && file.exists ()) {//Determine if the file exists &NBSP ; InputStreamReader read = new InputStreamReader ( &NBSP ; New FileInputStream (file), encoding);//considering the encoding format BufferedReader BufferedReader = new BufferedReader (read); String linetxt = NULL;&N Bsp //Perform update operation &nbs P while ((Linetxt = Bufferedreader.readline ()) = null) { &NBsp System.out.print (linetxt); }&NBS P read.close ();}else{SYSTEM.OUT.PRINTLN ("* * * Cannot find the file specified");}} catch (Exception e) {System.out.println ("Error reading file contents"); E.printstacktrace (); } }
Java Read TXT file