比如我在com/aa/bb下放了一个resource.properties文件,在同一包下的类读取它的路径可以这样:
InputStream is = PropertiesInfo.class.getResourceAsStream("resource.properties");
但我这个类还要实现写入的功能,如何才能得到该文件的路径啊?

解决方案 »

  1.   

    URL = new URL("resource.properties");
    然后你看着办吧!另外,如果拿不到
    URL = new URL("com/aa/bb/resource.properties");
      

  2.   

    不行呀。要写入properties文件,就得使用FileOutputStream来定位文件,要以File作为它的参数,我这样使用,但总是提示找不到文件:
    new FileOutputStream(new File(new URL("com/aa/bb/resource.properties").toURI()));
    或者:
    new FileOutputStream(new File(new URL("resource.properties").toURI()));
    都不行,请问如何是好?这个配置文件由于特殊原因,不能直接放到classpath下。
      

  3.   

       getClass().getResourceAsStream("FileName"); 
      getClass().getResource("File");