Java GuardedObject create and save
import java.io.FileOutputStream; import java.io.ObjectOutputStream; import java.security.Guard; import java.security.GuardedObject; import java.util.PropertyPermission; public class Main { public static void main(String[] args) throws Exception { Guard guard = new PropertyPermission("usr.home", "read"); String pass = new String("123456"); GuardedObject go = new GuardedObject(pass, guard); ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("pass")); oos.writeObject(go);// w w w.jav a2 s . c o m } }