情况是这样的:init.properties文件和可运行的.jar文件在同一目录下 init.properties是.jar的一些配置信息。现在是这样,init.properties在jar里边怎么读取都没问题,但是properties和.jar文件在同一目录下就不会弄了,希望各位大侠帮忙解决。

解决方案 »

  1.   

    可以参考一下这个:
    http://blog.csdn.net/sunyujia/archive/2008/09/21/2957481.aspx
      

  2.   

    如果用相对路径的话,看看../能不能访问。
    绝对路径的话,.jar能知道自己所在的目录,那也就知道properties所在的目录了
      

  3.   

    使用File file = new File("init.properties")
    就可以取得文件对象,就可以操作了
      

  4.   

    现在的难点是如何取到init.properties所在目录的绝对路径。
      

  5.   

     Properties ini = null;
     String path=类名.class.getResource("包名/配置文件");
     File file=null;
    static {
               try {
                   ini = new Properties ();
                   file=new File(path);
                    ini.load (file);
                    }catch (Exception ex) {
                     JOptionPane.showMessageDialog (null, "读取配置文件失败", "错误", JOptionPane.ERROR_MESSAGE);
                     ex.printStackTrace();
                    }
            }