通用类
package shopmanager;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author Linh
*/
public class Warehouse<T> {
private List<T> Product;
public void output() {
if (Product != null && !Product.isEmpty()) {
List<T> c;
for (int i = 0; i < Product.size(); i++) {
System.out.println(Product.get(i));
}
}
}
public void add(List<T> Product) {
this.Product = Product;
try {
save();
} catch (IOException ex) {
Logger.getLogger(Warehouse.class.getName()).log(Level.SEVERE, null, ex);
}
}
public List<T> getProduct() {
if (Product == null) {
Product = new ArrayList<T>();
}
return this.Product;
}
public void save() throws IOException{
FileOutputStream fs=new FileOutputStream("obj.dat");
ObjectOutputStream os=new ObjectOutputStream(fs);
os.writeObject(Product);
fs.close();
os.close();
}
}
如何将通用类保存并加载到文件中