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.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)); }// w w w .j a va2 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)); } 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 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(); } }