properties,你load以后是保存在内存的,所以你在程序里读是读到你写入的东西,但是如果你不手动指定保存到文件,你的更新是不是自己写入文件的,所以你看文件里的内容是没变的

解决方案 »

  1.   


    以上是废话,实测lz代码没问题,是路径取错了,
    fos = new FileOutputStream(this.getClass().getClassLoader().getResource("dbParameters.properties").getPath());
    不能这样取
    fos = new FileOutputStream(new File("D://test.txt"));
    你把这一句一替换,就可以看到结果了
      

  2.   


    以上是废话,实测lz代码没问题,是路径取错了,
    fos = new FileOutputStream(this.getClass().getClassLoader().getResource("dbParameters.properties").getPath());
    不能这样取
    fos = new FileOutputStream(new File("D://test.txt"));
    你把这一句一替换,就可以看到结果了fos = new FileOutputStream(this.getClass().getClassLoader().getResource("dbParameters.properties").getPath());
    通过classpath取到的路径,是你classpath下的路径,说白了,是你的编译路径,一般来说是bin目录,你肯定是在src下找,所以看到文件没有变,谐星的原因是,童鞋,你找错洞了
      

  3.   


    以上是废话,实测lz代码没问题,是路径取错了,
    fos = new FileOutputStream(this.getClass().getClassLoader().getResource("dbParameters.properties").getPath());
    不能这样取
    fos = new FileOutputStream(new File("D://test.txt"));
    你把这一句一替换,就可以看到结果了fos = new FileOutputStream(this.getClass().getClassLoader().getResource("dbParameters.properties").getPath());
    通过classpath取到的路径,是你classpath下的路径,说白了,是你的编译路径,一般来说是bin目录,你肯定是在src下找,所以看到文件没有变,谐星的原因是,童鞋,你找错洞了请教大神我应该怎么修改这句代码
      

  4.   

    不用改啊,你的代码又没错,properties文件也已经修改成功了,是你自己找错了地方所以才以为没改成功System.out.println(this.getClass().getClassLoader().getResource("dbParameters.properties").getPath())
    你把这个路径打印出来一看就知道了