当前位置: 移动技术网 > IT编程>开发语言>Java > Java 代码读取properties文件

Java 代码读取properties文件

2019年11月25日  | 移动技术网IT编程  | 我要评论

jdk1.6

package read;
import java.io.file;
import java.io.fileinputstream;
import java.io.ioexception;
import java.io.inputstreamreader;
import java.util.properties;

public class fileread {

    public static void main(string[] args) {
        fileread re=new fileread();
        string x=re.gete();
        system.out.println(x);
    }           
    public string gete(){
        properties props = new properties();
        system.out.println(new file("").getabsolutepath());
        try {
            props.load(new inputstreamreader(new fileinputstream(new file("").getabsolutepath()+"/src/config/read.properties"), "utf-8"));
        } catch (ioexception e) {
            // todo auto-generated catch block
            e.printstacktrace();
        }   
        string isuse = props.getproperty("isuse");
        return isuse;
    }

}

 

 

 

 jdk1.7及以上

import java.io.inputstream;
import java.util.properties;

        properties pro = new properties();
            try(inputstream is = getclass().getresourceasstream(
                    "/config/multi-language-configuration.properties")) {
                pro.load(is);
            } catch (exception e) {           
            }
            string isuse = pro.getproperty("isuse");

 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网