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;
    }

}
Java 代码读取properties文件

 

 Java 代码读取properties文件

 

 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");

 

相关文章:

  • 2022-01-16
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-20
  • 2022-02-11
  • 2022-12-23
  • 2021-05-23
  • 2021-12-19
  • 2021-05-19
相关资源
相似解决方案