Java Read TXT file

Source: Internet
Author: User

/** * 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 {  &nbsp ;         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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.