【发布时间】:2012-08-24 10:09:18
【问题描述】:
import java.io.*;
import java.util.Properties;
public class NewClass {
public static void main(String args[]) throws IOException {
Properties p = new Properties();
p.load(new FileInputStream("DBDriverInfo.properties"));
String url=p.getProperty("url");
String user=p.getProperty("username");
String pass=p.getProperty("password");
System.out.println(url+"\n"+user+"\n"+pass);
}
}
虽然DBDriverInfo.properties文件在同一个目录下,但还是会出现如下异常。
Exception in thread "main" java.io.FileNotFoundException: DBDriverInfo.properties (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.io.FileInputStream.<init>(FileInputStream.java:97)
at NewClass.main(NewClass.java:7)
在命令行界面中使用javac 编译时,相对路径可以正常工作。
但在 NetBeans 中引发了异常。
【问题讨论】:
标签: java netbeans properties netbeans-7 fileinputstream