FileUtils { public static InputStream getFileInputStream(String fileName) throws FileNotFoundException{ return getFileInputStream("./", fileName, FileUtils.class); }  static void recursiveDelete(File file); static String shortPath(String absolutePath); static String shortPath(String absolutePath, int level); static InputStream getFileInputStream(String fileName); static InputStream getFileInputStream(String path, String fileName); static InputStream getFileInputStream(String fileName, Class<?> clazz); static InputStream getFileInputStream(String path, String fileName, Class<?> clazz); static String readFileAsString(String fileName); static int DEFAULT_SHORT_PATH_LEVEL; }
@Test public void test() throws FileNotFoundException{ Assert.assertNotNull(FileUtils.getFileInputStream("fileutiltest.txt")); try{ FileUtils.getFileInputStream("fileutiltest_not_exist.txt"); Assert.fail(); }catch(FileNotFoundException e){ } }
@Test public void testAbsolute() throws IOException{ String testDir = getTestFileDir(); logger.info("[testAbsolute]{}", testDir); String fileName = getTestName() + ".txt"; File file = new File(testDir, fileName); String value = randomString(); org.apache.commons.io.FileUtils.write(file, value); InputStream ins = FileUtils.getFileInputStream(new File(testDir).getAbsolutePath(), fileName); Assert.assertNotNull(ins); }