Access Java Resource Files
In Java, you can use the ClassLoader class to access files in the resource folder. Here is an example code:
ClassLoader classLoader = getClass().getClassLoader();
InputStream inputStream = classLoader.getResourceAsStream("file.txt");
if(inputStream != null){
// 文件存在
// 可以读取文件内容
} else {
// 文件不存在
}
In the code above, first, we obtain the ClassLoader object, and then use the getResourceAsStream() method to get the input stream of the specified file. If the file exists, we can read the file content. If the file does not exist, the input stream will be null.