我的properties文件version=3我怎么通过代码把这个3改成2????求详细操作代码!!!!

解决方案 »

  1.   

    **
    * 修改或添加键值对 如果key存在,修改 反之,添加。

    * @param key
    * @param value
    */
    public static void writeData(String key, String value) {
    Properties prop = new Properties();
    try {
    File file = new File(PROPERTY_FILE);
    if (!file.exists())
    file.createNewFile();
    InputStream fis = new FileInputStream(file);
    prop.load(fis);
    fis.close();//一定要在修改值之前关闭fis
    OutputStream fos = new FileOutputStream(PROPERTY_FILE);
    prop.setProperty(key, value);
    prop.store(fos, "Update '" + key + "' value");
    fos.close();
    } catch (IOException e) {
    System.err.println("Visit " + PROPERTY_FILE + " for updating "
    + value + " value error");
    }
    }} 
      

  2.   


    File file = new File("D://param.properties"); 
    FileInputStream fis = null;
    FileOutputStream fos = null;
    try {
    fis = new FileInputStream(file);
    Properties prop = new Properties();
    prop.load(fis);
    prop.setProperty("key", "3");
    fos = new FileOutputStream(file);
    prop.store(fos, null);
    } catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }finally{
    try {
    fis.close();
    fos.close();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }

    }
      

  3.   

    他是static 里的一个方法  记得 好像这个可以直接被  static  main的对象调用
      

  4.   


    4楼的代码够清晰了。
    只需要把prop.setProperty("key", "3");中的key改为你的version就可以了。难道楼主都看不懂?