把一些与安全相关的常量可以放在PROPERTIES文件中,动态读取,可以提高安全性
举例:当面显示旅客图片时,我们可以通过传递文件名给一个servlet
在其中补全图片的全路径,然后再显示到页面
这样做的好处,在页面看不到图片的存储目录结构,其中补全全路径时,我们可以把图片路径做成可配置的放到*。properties中,这样以后目录变了也不用更改代码
package com.hunau.liuyong;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;
public class ReadPropertyies {
    public String getImage(String name) {
        String tem = "defaule name";
        try {
            /*
             * InputStream in =
             * getClass().getResourceAsStream("test.properties"); Properties p =
             * new Properties(); p.load(in); tem = p.get(name).toString();
             */
            InputStream in = new FileInputStream("E:\\test\\test2.properties");
            ResourceBundle rb = new PropertyResourceBundle(in);
            tem = rb.getString(name);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return tem;
    }
    public static void main(String[] args) {
        ReadPropertyies rp = new ReadPropertyies();
        String name = rp.getImage("name");
        System.out.println("NAME=" + name);
    }
}