Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package Lamlai;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.ObjectInputStream;
- import java.io.ObjectOutputStream;
- import java.util.ArrayList;
- /**
- *
- * @author leo
- */
- public class DocGhi {
- public DocGhi() {
- }
- public void DocFile(String f, ArrayList<Student> arrSV) {
- try {
- Student test = new Student();
- FileInputStream fis = new FileInputStream(f);
- ObjectInputStream in1 = new ObjectInputStream(fis);
- do {
- test = (Student) in1.readObject();
- arrSV.add(new Student(test.getTen(), test.getTuoi()));
- } while (test != null);
- in1.close();
- } catch (Exception e) {
- // System.out.println("Error - Open");
- }
- }
- public void GhiFile(String f, ArrayList<Student> arrSV) {
- try {
- FileOutputStream fos = new FileOutputStream(f);
- ObjectOutputStream out = new ObjectOutputStream(fos);
- for (int i = 0; i < arrSV.size(); i++) {
- Student sv = (Student) arrSV.get(i);
- out.writeObject(sv);
- }
- out.flush();
- out.close();
- } catch (Exception ee) {
- System.out.println("Error");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment