Java Convert File to String - A concise way.

File Reading

Reading content of a Character file and building a final String can be done with many a mechanisms depends upon various performance considerations.

A concise way would be
InputStream is = new FileInputStream(new File("pathtofile")); //Acquire the stream!
String content = new Scanner(is).useDelimiter("\\A").next(); // swallow it!
Converting an InputStream to String concisely is
String content = new Scanner(is).useDelimiter("\\A").next();



Comments

Popular posts from this blog

SVN File Creation Date

Java NIO2 - Watching a directory for changes. FileWatcherService.

Ubuntu / kubuntu - Laptop key board cursor jumping issue