DBuser=anonymous
DBpassword=&8djsx
DBlocation=bigone
--------------------------------------------------------------------
class ReadandWrite {
public static void main(String args[]) {
ReadandWrite props = newReadandWrite();
props.readit();
props.writeit();
}
public void readit() {
try{
Properties p = new Properties();
p.load(new FileInputStream("user.properties"));
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);
}
}
public void writeit() {}
try{
Properties p = new Properties();
p.load(new FileInputStream("user.properties"));
p.list(System.out);
// new Property
p.put("today", new Date().toString());
// modify a Property
p.put("DBpassword","foo");
FileOutputStream out = new FileOutputStream("myuser.properties");
p.save(out, "/* properties updated */");
}
catch (Exception e) {
System.out.println(e);
}
}
No comments:
Post a Comment