Java 读取解密文件 - 文件未找到异常
Java reading decrypted file - file not found exception
我正在尝试读取解密的 属性 文件。
文件位置是/WEB-INF/classes/db.properties
解码器java文件是src/a2.util/Decoder.java
它有一个名为 readFile(String fileName)
的方法。
当我这样调用方法时:
Decoder.readFile("db.properties")
我收到文件未找到异常。说..
db.properties (System cannot find specified file)
有人可以帮我解决这个问题吗?
如上无法访问
您可以获得真实路径:
ServletContext context = this.getServlet().getServletContext();
String fullPath = context.getRealPath("/WEB-INF/classes/db.properties");
或
java.net.URL url = [ClassName].class.getClassLoader().getResource("/WEB-INF/classes/db.properties");
除非这样尝试:
InputStream inputStream = servletContext.getResourceAsStream("/WEB-INF/classes/db.properties");
或
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("/db.properties");
我正在尝试读取解密的 属性 文件。
文件位置是/WEB-INF/classes/db.properties
解码器java文件是src/a2.util/Decoder.java
它有一个名为 readFile(String fileName)
的方法。
当我这样调用方法时:
Decoder.readFile("db.properties")
我收到文件未找到异常。说..
db.properties (System cannot find specified file)
有人可以帮我解决这个问题吗?
如上无法访问
您可以获得真实路径:
ServletContext context = this.getServlet().getServletContext();
String fullPath = context.getRealPath("/WEB-INF/classes/db.properties");
或
java.net.URL url = [ClassName].class.getClassLoader().getResource("/WEB-INF/classes/db.properties");
除非这样尝试:
InputStream inputStream = servletContext.getResourceAsStream("/WEB-INF/classes/db.properties");
或
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("/db.properties");