用Java程序读取Java的属性文件
package propertiesreader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
/**
*
* @author
*/
public class PropertiesReader
{
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws FileNotFoundException, IOException
{
// TODO code application logic here
//Reading properties file in Java example
Properties props = new Properties();
FileInputStream fis = new FileInputStream("c:/jdbc.properties");
//loading properites from properties file
props.load(fis);
//reading proeprty
String username = props.getProperty("jdbc.username");
String driver = props.getProperty("jdbc.driver");
System.out.println("jdbc.username: " + username);
System.out.println("jdbc.driver: " + driver);
}
}
系统找不到此行中指定的文件
FileInputStream fis = new FileInputStream("c:/jdbc.properties");
这意味着什么?我该如何解决这个问题
# 1 楼答案
虽然我在linux中编写了更多代码,但我看到在windows中编写代码的人通常使用“:\”代替“:/”。再次检查文件是否存在,然后尝试“:\”或“:\”
见:file path Windows format to java format 你的情况正好相反