服务热线:13616026886

技术文档 欢迎使用技术文档,我们为你提供从新手到专业开发者的所有资源,你也可以通过它日益精进

位置:首页 > 技术文档 > JAVA > 新手入门 > 基础入门 > 查看文档

java读取配置文件例子


  本例子为读取配置文件,一般用作读取参数

/*
 * 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 

扫描关注微信公众号