[英]Read a Java's property file with a Java program
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中進行編碼的人們通常使用“:\\\\”代替“:/”。 再次檢查文件是否存在,然后嘗試“:\\\\”或“:\\”
請參閱: 文件路徑Windows格式轉換為Java格式您的情況恰好相反
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.