static public String readFile ( String filename ) throws IOException { try ( FileInputStream fin = new FileInputStream ( filename ) ) { InputStreamReader reader = new InputStreamReader ( fin , CDM . utf8Charset ) ; StringWriter swriter = new StringWriter ( 50000 ) ; UnsynchronizedBufferedWriter writer = new UnsynchronizedBufferedWriter ( swriter ) ; writer . write ( reader ) ; return swriter . toString ( ) ; } }
Read the contents from the named file and place into a String assuming UTF - 8 encoding .