@Test public void testReadFileToString() throws IOException { String data = "test data"; File targetFile = temporaryFolder.newFile("targetFile.txt"); FileUtils.writeByteArrayToFile(targetFile, data.getBytes(), true); String content = FileUtils.readFileToString(targetFile, Charset.defaultCharset()); TestUtils.assertEqualContent(content.getBytes(), targetFile); }
public static String readFileToString(File file, Charset encoding) throws IOException { FileInputStream stream = new FileInputStream(file); try { Reader reader = new BufferedReader(new InputStreamReader(stream, encoding)); StringBuilder builder = new StringBuilder(); char[] buffer = new char[8192]; int read; while ((read = reader.read(buffer, 0, buffer.length)) > 0) { builder.append(buffer, 0, read); } return builder.toString(); } finally { stream.close(); } }
FileUtils { public static String readFileToString(File file, Charset encoding) throws IOException { FileInputStream stream = new FileInputStream(file); try { Reader reader = new BufferedReader(new InputStreamReader(stream, encoding)); StringBuilder builder = new StringBuilder(); char[] buffer = new char[8192]; int read; while ((read = reader.read(buffer, 0, buffer.length)) > 0) { builder.append(buffer, 0, read); } return builder.toString(); } finally { stream.close(); } } }
FileUtils { public static String readFileToString(File file, Charset encoding) throws IOException { FileInputStream stream = new FileInputStream(file); try { Reader reader = new BufferedReader(new InputStreamReader(stream, encoding)); StringBuilder builder = new StringBuilder(); char[] buffer = new char[8192]; int read; while ((read = reader.read(buffer, 0, buffer.length)) > 0) { builder.append(buffer, 0, read); } return builder.toString(); } finally { stream.close(); } }  }
FileUtils { public static String readFileToString(File file, Charset encoding) throws IOException { FileInputStream stream = new FileInputStream(file); try { Reader reader = new BufferedReader(new InputStreamReader(stream, encoding)); StringBuilder builder = new StringBuilder(); char[] buffer = new char[8192]; int read; while ((read = reader.read(buffer, 0, buffer.length)) > 0) { builder.append(buffer, 0, read); } return builder.toString(); } finally { stream.close(); } }  static void writeByteArrayToFile(File file, byte[] data); static void writeByteArrayToFile(File file, byte[] data, boolean append); static FileOutputStream openOutputStream(File file, boolean append); static void saveCommandHistory(List<int[]> history, File file); static List<int[]> loadCommandHistory(File file); static void saveCommandHistoryString(List<String> history, File file); static List<String> loadCommandHistoryString(File file); static String readFileToString(File file, Charset encoding); static Properties readProperties(String file); }
FileUtils { public static String readFileToString(File file, Charset encoding) throws IOException { FileInputStream stream = new FileInputStream(file); try { Reader reader = new BufferedReader(new InputStreamReader(stream, encoding)); StringBuilder builder = new StringBuilder(); char[] buffer = new char[8192]; int read; while ((read = reader.read(buffer, 0, buffer.length)) > 0) { builder.append(buffer, 0, read); } return builder.toString(); } finally { stream.close(); } }  static void writeByteArrayToFile(File file, byte[] data); static void writeByteArrayToFile(File file, byte[] data, boolean append); static FileOutputStream openOutputStream(File file, boolean append); static void saveCommandHistory(List<int[]> history, File file); static List<int[]> loadCommandHistory(File file); static void saveCommandHistoryString(List<String> history, File file); static List<String> loadCommandHistoryString(File file); static String readFileToString(File file, Charset encoding); static Properties readProperties(String file);  }