帮忙看看小问题

来源:百度知道 编辑:UC知道 时间:2024/07/07 23:16:25
我想从properties 文件中读数据库的几段代码;
但是怎么找不到指定文件呢,

String path=System.getProperty("user.dir")+"\\test.properties";
FileInputString fin=new FileInputStream(path);
Properties pro=new Properties();

pro.load(fin);
driver=pro.getProperty("dirver");

import java.io.*;
import java.util.*;

public class PropFileReader {
public static void main(String[] args) throws Exception {
String path = System.getProperty("user.dir")+"\\test.properties";
Properties prop = new Properties();
prop.load(new FileInputStream(path));
String driver = pro.getProperty("driver");
System.out.println(driver);
}
}

应该没问题。
前提条件是你的属性文件放在正确的路径中。
一般不建议使用user.dir系统属性定位文件夹位置。

System.out.println(path)

你看看目录吧。

属性文件应该放在 webRoot 目录下