Exp
 
private void init(ServletContext servletContext,LanguageFileConfig languageFileConfig) throws IOException {
    if (languages == null) {
      // Get available languages.
      availablelanguages = null;

      String availablelanguagesstring = languageFileConfig
          .getAvailableLanguagesAsString();
      availablelanguages = availablelanguagesstring.split(",");
      for (int i = 0; i < availablelanguages.length; i++) {
        availablelanguages[i] = availablelanguages[i].trim()
            .toUpperCase();
      }
      // Load available languages
      languages = new LanguageProperties[availablelanguages.length];
      for (int i = 0; i < availablelanguages.length; i++) {
        languages[i] = new LanguageProperties();
        String propsfile = "/" + languageFileConfig.getLanguagePath()
            + "/" + languageFileConfig.getLanguageFilename() + "."
            + availablelanguages[i].toLowerCase() + ".properties";

        InputStream is = null;
        if (servletContext != null) {
          is = servletContext.getResourceAsStream(propsfile);
        } else {
          is = this.getClass().getResourceAsStream(propsfile);
        }
        if (is == null) {
          // if not available as stream, try it as a file
          is = new FileInputStream("/tmp" + propsfile);
        }
        if (log.isDebugEnabled()) {
          log.debug("Loading language from file: " + propsfile);
        }
        languages[i].load(is);
      }
    }
  }
 
More
 
1.java.util.Properties类的load()    
        
示例:            
InputStream in = new BufferedInputStream(new FileInputStream(name));            
Properties p = new Properties();            
p.load(in);            
        
2.java.util.ResourceBundle类的getBundle()
    
示例:        
ResourceBundle rb = ResourceBundle.getBundle(name, Locale.getDefault());            
        
3.java.util.PropertyResourceBundle类的构造函数
            
示例:            
InputStream in = new BufferedInputStream(new FileInputStream(name));            
ResourceBundle rb = new PropertyResourceBundle(in);            
        
4.class变量的getResourceAsStream()方法        
    
示例:            
InputStream in = JProperties.class.getResourceAsStream(name);            
Properties p = new Properties();            
p.load(in);            
        
5.class.getClassLoader()所得到的java.lang.ClassLoader的getResourceAsStream()方法        
    
示例:            
InputStream in = JProperties.class.getClassLoader().getResourceAsStream(name);            
Properties p = new Properties();            
p.load(in);            
        
6.java.lang.ClassLoader类的getSystemResourceAsStream()静态方法    
        
示例:            
InputStream in = ClassLoader.getSystemResourceAsStream(name);            
Properties p = new Properties();            
p.load(in);            
        
7. Servlet中可以使用javax.servlet.ServletContext的getResourceAsStream()方法
            
示例:        
InputStream in = context.getResourceAsStream(path);            
Properties p = new Properties();            
p.load(in);