@Test public void testReadFileAsString() throws IOException { String text = "Hello World\n\tasdasdasdas"; String text2 = "Han Solo is the best star wars character"; File file = File.createTempFile("TEST", ".txt"); file.deleteOnExit(); BufferedWriter writer = new BufferedWriter(new FileWriter(file)); writer.write(text); writer.flush(); String readString = BulldogUtil.readFileAsString(file.getAbsolutePath()); TestCase.assertEquals(text, readString); readString = BulldogUtil.readFileAsString("DOES NOT EXIST"); TestCase.assertNull(readString);; writer.write(text2); writer.flush(); readString = BulldogUtil.readFileAsString(file.getAbsolutePath()); TestCase.assertEquals(text + text2, readString); writer.close(); }
public static String readFileAsString(String path) { try { byte[] encoded = Files.readAllBytes(Paths.get(path)); return new String(encoded, Charset.defaultCharset()); } catch(Exception ex) { return null; } }
BulldogUtil { public static String readFileAsString(String path) { try { byte[] encoded = Files.readAllBytes(Paths.get(path)); return new String(encoded, Charset.defaultCharset()); } catch(Exception ex) { return null; } } }
BulldogUtil { public static String readFileAsString(String path) { try { byte[] encoded = Files.readAllBytes(Paths.get(path)); return new String(encoded, Charset.defaultCharset()); } catch(Exception ex) { return null; } }  }
BulldogUtil { public static String readFileAsString(String path) { try { byte[] encoded = Files.readAllBytes(Paths.get(path)); return new String(encoded, Charset.defaultCharset()); } catch(Exception ex) { return null; } }  static void sleepMs(int ms); static void sleepNs(int ns); static String bytesToString(byte[] bytes, String encoding); static String bytesToString(byte[] bytes); @SuppressWarnings("resource") static String convertStreamToString(java.io.InputStream is); static String readFileAsString(String path); static boolean isStringNumeric(String str); static final int getUnsignedByte(byte b); }
BulldogUtil { public static String readFileAsString(String path) { try { byte[] encoded = Files.readAllBytes(Paths.get(path)); return new String(encoded, Charset.defaultCharset()); } catch(Exception ex) { return null; } }  static void sleepMs(int ms); static void sleepNs(int ns); static String bytesToString(byte[] bytes, String encoding); static String bytesToString(byte[] bytes); @SuppressWarnings("resource") static String convertStreamToString(java.io.InputStream is); static String readFileAsString(String path); static boolean isStringNumeric(String str); static final int getUnsignedByte(byte b);  }