Source Code : Compress Java objects
Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com.
Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com.
Click Here or search from google with Libraries Name you get jar file related it
Compress Java objects
import java.io.File;
import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.zip.GZIPOutputStream;
public class Main {
public static void main(String[] args) throws Exception {
User admin = new User();
admin.setId(new Long(1));
User foo = new User();
foo.setId(new Long(2));
ObjectOutputStream oos = new ObjectOutputStream(new GZIPOutputStream(new FileOutputStream(new File("user.dat"))));
oos.writeObject(admin);
oos.writeObject(foo);
oos.flush();
oos.close();
}
}
class User implements Serializable {
private Long id;
public User() {
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("id=").append(id);
return sb.toString();
}
}
Thank with us