Static method file path

1.4k views Asked by At

How do i get the Path of a file in the same package as the class?

This doesn't work.

public static void SaveAllMockData() throws Exception {


        InputStream inputStream = getClass().getClassLoader().getResourceAsStream("mockdata.json");

    }
1

There are 1 answers

1
Thusitha Thilina Dayaratne On BEST ANSWER

You can use

InputStream is = YourClassName.class.getResourceAsStream("mockdata.json"");

or you can specify the package path

getClass()
    .getResourceAsStream("/abc/efg/mockdata.json");