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");
这是什么意思以及如何解决这个问题?
最佳答案
虽然我在 Linux 中编码较多,但我看到在 Windows 中编码的人通常使用“:\\”代替“:/”。再次检查文件是否存在并尝试“:\\”或“:\”
请参阅:file path Windows format to java format
你的情况正好相反
关于java - 用Java程序读取Java的属性文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29468264/