首先介绍一下通过Properties读取配置文件的方式,其实也是一种读取流,不多说,直接看代码:
test.properties中的内容如下:
userDaoClass=com.huawi.JDBC.Impl.UserDaoJdbcImpl
ProTest读取配置文件代码如下:
public class ProTest {
/**
* @param args
* @throws IOException
* @throws FileNotFoundException
*/
public static void main(String[] args) throws FileNotFoundException, IOException {
// TODO Auto-generated method stub
readPro();
}
public static void readPro() throws FileNotFoundException, IOException
{
Properties properties=new Properties();
properties.load(new FileInputStream(new File("src/test.properties")));
String result=properties.getProperty("userDaoClass");
System.out.println(result);
}
}
输出:com.huawi.JDBC.Impl.UserDaoJdbcImpl