Constants.java
wapoffline-config.propertiesConstants.java:如下
package com.zhangxy;import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;public class Constants
{
    //跳转页面配置信息
    public static final String LOGINSUCCESS = "LoginSucess";
    public static final String LOGINFAILD = "LoginFaild";
    
    //系统信息配置文件
    public static final String CONFIG_FILE_PATH = "wapoffline-config.properties";
    public static Properties properties = new Properties();
    
    static {
        try{
            //InputStream in = Constants.class.getResourceAsStream("wapoffline-config.properties");            InputStream in = new FileInputStream(new File(Constants.CONFIG_FILE_PATH));
            properties.load(in);
        }catch (FileNotFoundException e){
            e.printStackTrace();
        }catch (IOException e){
            e.printStackTrace();
        }        
    }
}
wapoffline-config.properties 文件如下:
#The passport for login ExpMenuSys 
LoginSystem.UserName = zhangxy
LoginSystem.PassWord = zhangxy

解决方案 »

  1.   

    这里new File()的prefix path不是当前class的,是启动这个应用的路径,
    你可以用File.getAbsolutePath ()打印出当前的prefix path是多少,然后在new 这个File。
    例如当前prefix path是: D:\Web\, 那你这样做:
    InputStream   in   = 
    new   FileInputStream(new   File(“WEB-INF\\classes\\com\\zhangxy\\”+CONFIG_FILE_PATH)); 
      

  2.   

    InputStream   in   =   Constants.class.getClassLoader().getResourceAsStream("wapoffline-config.properties"); 
    试试这个。
      

  3.   

    异常是FileInputStream抛出来的
    我还以为是new File()时候抛出来的呢
    谁能告诉我为什么?
      

  4.   

    异常确实是FileInputStream抛出来的。因为new File()不会判断file实际存不存在,你可以通过File.exists()来判断文件是否存在。
    而FileInputStream在读取文件内容的时候会抛出文件找不到异常。