Read a file from resources folder in Java

String fileName="build.txt";
ClassLoader classLoader = getClass().getClassLoader();
InputStream in = classLoader.getResourceAsStream(fileName);
BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(in));
String buildNumberStr= bufferedReader.readLine();
bufferedReader.close();
result=buildNumberStr;

References
https://www.mkyong.com/java/java-read-a-file-from-resources-folder/

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.