Quantcast
Viewing all articles
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 all articles
Browse latest Browse all 36

Trending Articles