Java tutorial
//package com.java2s; import java.io.*; import java.util.Scanner; public class Main { public static String readFile(String pathname) { File file = new File(pathname); StringBuilder fileContents = new StringBuilder((int) file.length()); String lineSeparator = System.getProperty("line.separator"); try { try (Scanner scanner = new Scanner(file)) { while (scanner.hasNextLine()) { fileContents.append(scanner.nextLine()).append(lineSeparator); } return fileContents.toString(); } } catch (FileNotFoundException e) { e.printStackTrace(); } return ""; } }