Java: Getting the contents of a file

Source: Internet
Author: User

Article Source: https://www.cnblogs.com/hello-tl/p/9139353.html

Import java.io.*;p Ublic class Filebasicoperation {/** * get file Contents * @param filePath * @return */@SuppressWarnings ("Reso            Urce ") Public String getfilecontent (string filePath) {try {File file = new file (FilePath); if (File.isfile () && file.exists ()) {InputStreamReader read = new InputStreamReader (New fileinputs                Tream (file), "UTF-8");                BufferedReader BufferedReader = new BufferedReader (read);                String linetxt = Bufferedreader.readline ();                while (linetxt! = null) {return linetxt;            }}else{return "There is no file"; }} catch (Unsupportedencodingexception |            FileNotFoundException e) {System.out.println ("Cannot find the file specified!");        E.printstacktrace ();            } catch (IOException e) {System.out.println ("Error reading file content!");        E.printstacktrace (); } return null;}}    

Article Source: https://www.cnblogs.com/hello-tl/p/9139353.html

Java: Getting the contents of a 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.