Quantcast
Viewing latest article 18
Browse Latest Browse All 36

Answer by Ilya Gazman for How do I create a Java string from the contents of a file?

If you do not have access to the Files class, you can use a native solution.

static String readFile(File file, String charset)        throws IOException{    FileInputStream fileInputStream = new FileInputStream(file);    byte[] buffer = new byte[fileInputStream.available()];    int length = fileInputStream.read(buffer);    fileInputStream.close();    return new String(buffer, 0, length, charset);}

Viewing latest article 18
Browse Latest Browse All 36

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>