JAVA读取Properties文件

JAVA读取Properties文件的方法

       在web项目开发中,经常遇到配置文件的读取,配置文件一般是XML文件或Properties文件,下面是Properties文件的读取方法:

1.假设在WEB-INF目录项存在配置文件conf.properties,它的内容如下所示:

serIP=127.0.0.1
serPort=6400

2.在Action或servlet中读取的方法:

Properties p = new Properties();
String filePath = request.getSession().getServletContext().getRealPath("\WEB-INF")+"\conf.properties"; //取得文件存放的路径
p.load(new FileInputStream(new File(filePath)));
String stuffPath ="http://"+ p.getProperty("serIP")+":"+p.getProperty("serPort")+"/devAdm/upload/";
原文地址:https://www.cnblogs.com/zhougaojun/p/3624017.html