import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
public class Test {
public static void main(String[] args) {
Singleton s1 = Singleton.getInstance();
Singleton s2 = null;
FileOutputStream fos = null;
try{
fos = new FileOutputStream("SeriableSingleton.obj");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(s1);
oos.flush();
oos.close();
FileInputStream fis = new FileInputStream("SeriableSingleton.obj");
ObjectInputStream ois = new ObjectInputStream(fis);
s2 = (Singleton) ois.readObject();
ois.close();
System.out.println(s1 == s2);
}catch (Exception e){
e.printStackTrace();
}
}
}
通过序列化和反序列化攻击单例
最新推荐文章于 2024-09-10 23:16:22 发布
关键词由CSDN通过智能技术生成