日期:2014-05-20  浏览次数:20744 次

高人看看,读取properties文件报错了
源文件:

import   java.util.*;
import   java.io.*   ;

public   class   FindProperty{
    private   Properties   props;
   
public   FindProperty()   {
        }

public     static   String       getProperties   (String   string)   throws   IOException{
 
          Properties   props=new   Properties();
          FileInputStream     in   =new   FileInputStream( "some.properties ");  
          props.load(in);
          in.close();
          return   props.getProperty(string);  
  }
   
}
some.properites文件和class文件放在同一个文件夹下,然后打包成一个jar,然后运行,就报错   "some.properties:系统找不到指定文件 "  
高手看看,我该怎么弄才能正常运行.谢了,最后的30分全给你了


 


------解决方案--------------------
如果你这个 some.properties 是必须要放在 jar 里面的,可以参考 velocity 这样的写法:

final static String DEFAULT_RUNTIME_PROPERTIES =
"org/apache/velocity/runtime/defaults/velocity.properties ";

private void setDefaultProperties()
{
try
{
InputStream inputStream = getClass()
.getResourceAsStream( '/ ' + DEFAULT_RUNTIME_PROPERTIES);

configuration.load( inputStream );
......