class MyClass { private void readFromFile() { getClass().getClassLoader().getResourceAsStream("file_path"); } }Somehow this will only work only if it is an instance object. What if I’m reading the file from a static method? The code below shows the solution:
class MyClass { private static void readFromFile() { MyClass.class.getClassLoader().getResourceAsStream("file_path"); } }
No comments:
Post a Comment