import java.io.*;
import java.util.*;
public class SetPro 
{
private String test_name;
private String test_user;
private String test_pwd;

public SetPro()
{
try
{
Properties props =new Properties();
test_name = props.setProperty("test_name","wbo");
test_user = props.setProperty("test_user","wb");
test_pwd =  props.setProperty("test_pwd","123");
File f = new File("E:\\test.properties");
FileOutputStream out = new FileOutputStream(f);
            props.store(out,test_name);
            props.store(out,test_user);
            props.store(out,test_pwd);
out.close();
}
catch(IOException e)
{
System.out.println(e);
}
}
}
想向目标文件写入系统属性,可是不通过.setProperty(String key, String value)不对吗,怎么不对呐.

解决方案 »

  1.   

    test_name = (String)props.setProperty("test_name","wbo");
    test_user = (String)props.setProperty("test_user","wb");
    test_pwd =  (String)props.setProperty("test_pwd","123");
    这么改下就可以编译过了.
    ==========================================================
    ==========================================================
    ==========================================================import java.io.*;
    import java.util.*;
    public class SetPro 
    {

    public SetPro(){
    try{
    Properties props =System.getProperties();
    File f = new File("E:\\test.properties");
    PrintStream out = new PrintStream(f);
    props.list(out);
    out.close();
    }
    catch(IOException e){
    System.out.println(e);
    }
    }
             public static void main(String[] args){
         SetPro sp = new SetPro();
             }
    }
    这个例子向目标文件写入系统属性