FileUtil { public static byte[] readFile(File f) throws IOException { FileInputStream bprInputStream = null; try { bprInputStream = new FileInputStream(f); ByteArrayOutputStream bytesOut = new ByteArrayOutputStream((int) f.length()); IOUtils.copy(bprInputStream, bytesOut); return bytesOut.toByteArray(); } finally { IOUtils.closeQuietly(bprInputStream); } } private  FileUtil(); static File createTempDirectory(); static byte[] readFile(File f); static String getFileNameWithoutSuffix(String fileName);  }
@Test public void testReadFile() throws Exception { String fileName = "src/test/resources/" + getClass().getName().replaceAll("\\.", "/") + ".txt"; File f = new File(fileName); assertTrue("Test set-up correct: " + f.getAbsolutePath(), f.exists()); byte[] contents = FileUtil.readFile(f); assertEquals(3, contents.length); assertArrayEquals(new byte[] { 'a', 'b', 'c' }, contents); }