@Test public void testLoadFileFromClasspath() throws Exception { final String contents = ClasspathHelper.loadFileFromClasspath("classpathTest.txt"); assertEquals(contents, "How now brown cow?"); }
public static String loadFileFromClasspath(String location) { InputStream inputStream = ClasspathHelper.class.getResourceAsStream(location); if(inputStream == null) { inputStream = ClasspathHelper.class.getClassLoader().getResourceAsStream(location); } if(inputStream == null) { inputStream = ClassLoader.getSystemResourceAsStream(location); } if(inputStream != null) { try { return IOUtils.toString(inputStream); } catch (IOException e) { throw new RuntimeException("Could not read " + location + " from the classpath", e); } } throw new RuntimeException("Could not find " + location + " on the classpath"); }
ClasspathHelper { public static String loadFileFromClasspath(String location) { InputStream inputStream = ClasspathHelper.class.getResourceAsStream(location); if(inputStream == null) { inputStream = ClasspathHelper.class.getClassLoader().getResourceAsStream(location); } if(inputStream == null) { inputStream = ClassLoader.getSystemResourceAsStream(location); } if(inputStream != null) { try { return IOUtils.toString(inputStream); } catch (IOException e) { throw new RuntimeException("Could not read " + location + " from the classpath", e); } } throw new RuntimeException("Could not find " + location + " on the classpath"); } }
ClasspathHelper { public static String loadFileFromClasspath(String location) { InputStream inputStream = ClasspathHelper.class.getResourceAsStream(location); if(inputStream == null) { inputStream = ClasspathHelper.class.getClassLoader().getResourceAsStream(location); } if(inputStream == null) { inputStream = ClassLoader.getSystemResourceAsStream(location); } if(inputStream != null) { try { return IOUtils.toString(inputStream); } catch (IOException e) { throw new RuntimeException("Could not read " + location + " from the classpath", e); } } throw new RuntimeException("Could not find " + location + " on the classpath"); }  }
ClasspathHelper { public static String loadFileFromClasspath(String location) { InputStream inputStream = ClasspathHelper.class.getResourceAsStream(location); if(inputStream == null) { inputStream = ClasspathHelper.class.getClassLoader().getResourceAsStream(location); } if(inputStream == null) { inputStream = ClassLoader.getSystemResourceAsStream(location); } if(inputStream != null) { try { return IOUtils.toString(inputStream); } catch (IOException e) { throw new RuntimeException("Could not read " + location + " from the classpath", e); } } throw new RuntimeException("Could not find " + location + " on the classpath"); }  static String loadFileFromClasspath(String location); }
ClasspathHelper { public static String loadFileFromClasspath(String location) { InputStream inputStream = ClasspathHelper.class.getResourceAsStream(location); if(inputStream == null) { inputStream = ClasspathHelper.class.getClassLoader().getResourceAsStream(location); } if(inputStream == null) { inputStream = ClassLoader.getSystemResourceAsStream(location); } if(inputStream != null) { try { return IOUtils.toString(inputStream); } catch (IOException e) { throw new RuntimeException("Could not read " + location + " from the classpath", e); } } throw new RuntimeException("Could not find " + location + " on the classpath"); }  static String loadFileFromClasspath(String location);  }