Here you can find the source of readAsString(File file)
public static String readAsString(File file) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.*; import java.nio.charset.Charset; import java.nio.file.*; import javax.swing.*; import javax.swing.filechooser.FileNameExtensionFilter; public class Main { public static String readAsString(String path) throws IOException { return readAsString(new File(path)); }/*from w w w .j a v a 2 s . co m*/ public static String readAsString(File file) throws IOException { return readAsString(file.toPath()); } public static String readAsString(Path path) throws IOException { return new String(Files.readAllBytes(path), Charset.forName("US-ASCII")); } public static String readAsString(JFrame frame, String ext, String desc) throws IOException { File file = findFileOpen(frame, ext, desc); if (file == null) { return null; } return readAsString(file); } public static String readAsString(InputStream input) throws IOException { String line; StringBuilder builder = new StringBuilder(); InputStreamReader streamReader = new InputStreamReader(input, Charset.forName("US-ASCII")); BufferedReader reader = new BufferedReader(streamReader); while ((line = reader.readLine()) != null) { builder.append(line); builder.append("\n"); } return builder.toString(); } public static File findFileOpen(JFrame frame, String ext, String desc) { JFileChooser chooser = new JFileChooser(); chooser.setFileFilter(new FileNameExtensionFilter(desc, ext)); if (chooser.showOpenDialog(frame) != JFileChooser.APPROVE_OPTION) { return null; } return chooser.getSelectedFile(); } }