Chinaunix

标题: JAVA读取INI文件一 [打印本页]

作者: hkebao    时间: 2008-11-14 21:25
标题: JAVA读取INI文件一
研究JAVA来读取INI文件一下午,终于搞出来了一个。但是比较遗憾的是在WEB应用中还是不能成功!
现在我将我的代码贴出来:
package tmp;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
public class Test {
    public static void main(String[] args){        
        Properties p = new Properties();
        FileInputStream fs = null;
        try{
            fs=new FileInputStream("./temp.ini");//这个地方要特别注意
            p.load(fs);
            String s;
            s=p.getProperty("hkebao");
            System.out.print(s);
        }catch(Exception e){
            System.out.print(e.toString());
        }finally{
            try{
                fs.close();
                p=null;
            }catch(Exception e){
                System.out.print(e.toString());
            }
        }
    }
}
其中我写的INI文件是如下:
hkebao=123
名字就是temp.ini
好了,现在要特别注意的是路径问题了!
如果我们的工程文件是放在:F:\专题讨论\java与配置文件总结\ConfigFirst
那么我们的这个temp.ini 文件得放在上面这个目录下面才行哦!
这个表示的是根目录了!
只需要将这个INI文件放在根 下面就可以了哦!
希望对各位如果想用INI作配置文件的朋友有所帮助。我在网上找了很多资料都没有用。所以这个我是通过测试的,没有问题可以用哦!
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/84280/showart_1415507.html




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2