***.jar
  my
   classes
      API.class
  META-INF
      ***.properties另外我也式过直接放在jar下面
***.jar
  my
   classes
      API.class
   ***.properties也不行eclipse 是这样的
myproject
 src
  my
    classes
      API.java( 里面调用 new FileInputStream("./***.properties");)
      Test.java
 ***.properties
这样的Test.java是可以运行的  

解决方案 »

  1.   

    应该在包的根根目录下,或者不用打包进jar,而和jar相同目录
      

  2.   

    问题是我是提供一个jar包给别人用的
    properties文件只是我自己用,不是给用户用的。
    放在根目录下也式过了,也不行
      

  3.   

    一般都是jar文件另外再加配置文件之类的
    ****.jar
    ****.pro....或者xml
    这样也方便用户修改,不过你要是想为了保密你就将文件的内容加一下密就行了。
    还没有看到jar里面包含配置文件的
      

  4.   

    我还是不明白,其实跟properties没有什么太大关系,问题就是怎样读取一个jar里的文件。
    这个properties是我自己内部程序里为了结果清楚一点用的,和调用的我api的用户无关。所以应该是在jar理的,大概例子如下 public void api()
     {
        loadParameterFromFile("***.properties") ;
        System.out.print("test"+properties.getProperty("name"));
     } static void loadParameterFromFile(String uri) {
            properties = new Properties();
            FileInputStream propertiesFileInputStream = null;
            try {
                propertiesFileInputStream = new FileInputStream(uri);
                properties.load(propertiesFileInputStream);
                if (logger.isInfoEnabled()) {
                    logger.debug("Properties-File '" + uri + "' loaded.");
                 }
            } catch (java.io.FileNotFoundException e) {
                propertiesFileInputStream = null;            logger.error("Properties-File '" + uri + "' not found.");           // e.printStackTrace();
            } catch (java.io.IOException e) {
                propertiesFileInputStream = null;            logger.error("Properties-File '" + uri + "' can not be read.");            e.printStackTrace();
            } finally {
                if (propertiesFileInputStream != null) {
                    try {
                        propertiesFileInputStream.close();
                    } catch (java.io.IOException e) {
                    }
                    propertiesFileInputStream = null;
                }
            }
        }
      

  5.   

    String strPath = ClassLoader.getSystemResource ("test/iniTest.ini").toString ().substring (6);
    iniFileP.load(new FileInputStream (strPath));//text是包名,把文件放在根目录下(跟类在一起,也可以建一个INI目录,然后带上目录)就行了,如下:
    String strPath = ClassLoader.getSystemResource ("test/ini/iniTest.ini").toString ().substring (6);
      

  6.   

    你试试下面的,不要用fileinputstream
                Properties properties = new Properties();
                properties.load(this.getClass().getResourceAsStream("/packagename/*.properties"));
      

  7.   

    文件打包进了JAR是读不到的
    如果楼主搞定了请通知一声
      

  8.   

    Acylas, 式了你的方法也不行。
    刚开始因为这应该是个很简单的问题
    假如用户用xml定义个东西,dtd应该在程序内部定义,这样的dtd不是应该由jar一起提供?要不然程序怎么验证xml的正确行,或者还有很多别的情况都要读取jar里的文件阿。jdk自带的dt.jar里
    javax/swing/beaninfo/images/里面的图片不是都是里面那个class调用的吗。怎么可能文件打包进jar就读不到了,这个我觉得是不可能的
      

  9.   

    http://community.csdn.net/Expert/TopicView.asp?id=3299149
      

  10.   

    http://search.chinaitlab.com/viewlist.asp?keywords=jar&Submit=%BC%BC%CA%F5%D7%CA%D4%B4%CB%D1%CB%F7&bigclass=1http://dev.csdn.net/article/31/31412.shtm
      

  11.   

    wingtrace贴的不是获取自己定义的Properties文件,而是系统的,
    getResourceAsStream这个用来获取包里面的图片、txt文件等都可以正常取得的。调试一下,不用要load方法,
    自己用这个this.getClass().getResourceAsStream("/packagename/*.properties")解析
      

  12.   

    的确是用getClass().getResourceAsStream解决了,问题是这样不是要两套程序,一套给eclipse开发时候用,一套最后打包用???怎么会这么复杂
      

  13.   

    打包后都可以用开发的时候也可以用的,又不是通过url之类的获取