java read file from resources code example
Example 1: java resource file
File file = new File(
getClass().getClassLoader().getResource("database.properties").getFile()
);
Example 2: java resource file
InputStream inputStream = getClass()
.getClassLoader().getResourceAsStream("database.properties");
Example 3: java read file
try (Stream<String> stream = Files.lines(Paths.get(String.valueOf(new File("yourFile.txt"))))) {
stream.forEach(System.out::println);
} catch (IOException e) {
e.printStackTrace();
}