本例子为读取配置文件,一般用作读取参数
/*
* created on 2004-9-21
*
* java读取配置文件例子
*/
package net.jspcn.test;
import java.util.*;
import java.io.*;
/**
* @author whilvydy
*
*/
public class test1 {
public string getpara(string filename) {
properties prop= new properties();
try {
inputstream is = getclass().getresourceasstream(filename);
prop.load(is);
if(is!=null) is.close();
}
catch(exception e) {
system.out.println(e+"file "+filename+" not found");
}
return prop.getproperty("file_name");
}
public static void main(string[] args) {
test1 test = new test1();
system.out.println(test.getpara("db.property"));
}
}
-----------------------------------
db.property内容如下:
file_name:winrar.exe
闽公网安备 35060202000074号