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