如何从java
中的指定路径读取文件代码
public void readPropertyFile(String path)throws IOException {
File fp = new File(path);
FileReader reader = new FileReader(fp);// java.io.FileNotFoundException: C:\json\trm\trm.jar\quartz.properties (The system cannot find the path specified)
Properties properties = new Properties();
properties.load(reader)
}
Exption:
java.io.FileNotFoundException: C:\json\trm\trm.jar\quartz.properties (The system cannot find the path specified)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(Unknown Source)....
答案 0 :(得分:0)
由于您正在从WAR(acm.war)或JAR(acm.jar)内部阅读,因此需要ZipInputStream
或JarInputStream
。
String entryName = "a.properties";
Path path = Paths.get("C:", "somefolder", "abc.war");
try (ZipInputStream zipIn = new ZipInputStream(Files.newInputStream(path))) {
ZipEntry entry;
while ((entry = zipIn.getNextEntry()) != null) {
if (entry.getName().equals(entryName) {
// read zipIn content here to get the entry
}
}
}