[xx]
x=x1
x2=x3
[xx1]
x=x1
x2=x3
[xx2]
x=x1
...
用Java读取值和更新值我找到了相应代码,就是添加根/变量。,我没找到代码,希望广大网友帮我找找,现成代码最好

解决方案 »

  1.   

    public void addInfo(String key, String value) { 
    try { 
    File file = new File("d:/aaa.ini"); 
    InputStream is = new FileInputStream(file); 
    p.load(is); 
    OutputStream fos = new FileOutputStream(file); 
    p.setProperty(key, value); 
    p.store(fos, null); 
    fos.flush(); 
    is.close(); 
    } catch (Exception ex) { 
    ex.printStackTrace(); 


      

  2.   

    public void addInfo(String key, String value) { 
    try { 
    File file = new File("d:/aaa.ini"); 
    InputStream is = new FileInputStream(file); 
    p.load(is); 
    OutputStream fos = new FileOutputStream(file); 
    p.setProperty(key, value); //这里有key的话就修改覆盖掉,没有就增加的 
    //p.remove(key); //这里是删除 
    p.store(fos, null); 
    fos.flush(); 
    is.close(); 
    } catch (Exception ex) { 
    ex.printStackTrace(); 

      

  3.   

    Java API for handling Windows ini file formathttp://ini4j.sourceforge.net/
      

  4.   

    [INI file : user.ini]DBuser=anonymous
    DBpassword=&8djsx
    DBlocation=bigoneimport java.util.*;
    import java.io.*;class readIni {
      public static void main(String args[]) {
        readIni ini = new readIni();
        ini.doit();
        }  public void doit() {
        try{
          Properties p = new Properties();
          p.load(new FileInputStream("user.ini"));
          System.out.println("user = " + p.getProperty("DBuser"));
          System.out.println("password = " + p.getProperty("DBpassword"));
          System.out.println("location = " + p.getProperty("DBlocation"));
          p.list(System.out);
          }
        catch (Exception e) {
          System.out.println(e);
          }
        }

      

  5.   

    如果是这个值
    [xx]
    xx=1
    xx1=2
    [xx1]
    xx=3
    xx1=4
      

  6.   

    这些方法我知道,最后我自己参照了几个类,写了下面的操作类: 
    http://bbs.svnfree.com/viewthread.php?tid=18&extra=