Rag*_*dra 3 java netbeans properties fileinputstream netbeans-7
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);
}
}
Run Code Online (Sandbox Code Playgroud)
虽然文件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)
Run Code Online (Sandbox Code Playgroud)
javac在命令行界面中编译时,相对路径工作正常.但NetBeans中的异常引发了异常.
| 归档时间: |
|
| 查看次数: |
21005 次 |
| 最近记录: |