Java Read File from Resources Folder!

Java — How to load a file from resources folder?

Sometime during tests you may want to read a file from resources folder; and here is the java code which you can use to read the file:

ClassLoader classloader = Thread.currentThread().getContextClassLoader();
// read as input stream
InputStream is = classloader.getResourceAsStream("GameOfThronesS01E01.m3u8");
// read as a file
File file = new File(classLoader.getResource("GameOfThronesS01E01.m3u8").getFile());

About The Author
Rasheed is TECH Enabler at @RapidStartupStudio. You can connect with him on LinkedIn.