Advertisement
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 L05;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.ObjectInputStream;
- import java.io.ObjectOutputStream;
- import java.util.ArrayList;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- /**
- *
- * @author Anh-Kool
- */
- public class GiFile {
- public String file = "data121.txt";
- void write(ArrayList<Student> students) {
- try {
- ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file, true));
- oos.writeObject(students);
- oos.close();
- } catch (IOException ex) {
- System.out.println("Ghi file loi");
- }
- }
- ArrayList<Student> read() {
- ArrayList<Student> students = new ArrayList<Student>();
- File file1 = new File(file);
- try {
- if (file1 != null) {
- FileInputStream fis = new FileInputStream(file);
- ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file));
- students = (ArrayList<Student>) ois.readObject();
- }
- } catch (IOException ex) {
- Logger.getLogger(GiFile.class.getName()).log(Level.SEVERE, null, ex);
- } catch (ClassNotFoundException ex) {
- Logger.getLogger(GiFile.class.getName()).log(Level.SEVERE, null, ex);
- }
- return students;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement