| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- package agenda;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.ObjectInputStream;
- import java.io.ObjectOutputStream;
- import javax.swing.JFileChooser;
- public class Io {
- public static void writeIo(Agenda agenda) throws IOException
- {
- JFileChooser fileChooser = new JFileChooser();
- if(fileChooser.showSaveDialog(null)
- == fileChooser.APPROVE_OPTION) {
- java.io.File file = fileChooser.getSelectedFile();
- ObjectOutputStream output = null;
- try{
- output = new ObjectOutputStream(new FileOutputStream(file));
- }catch(IOException e){
- System.out.println("Could not open file." + e);
- }
- try{
- output.writeObject(agenda);
- output.close();
- }catch(IOException e){
- System.out.println("Writing error. " + e);
- }
- }
- }
- public static Agenda readIo() throws IOException
- {
- JFileChooser fileChooser = new JFileChooser();
- if(fileChooser.showOpenDialog(null)
- == fileChooser.APPROVE_OPTION) {
- java.io.File file = fileChooser.getSelectedFile();
- ObjectInputStream input = null;
- try{
- input = new ObjectInputStream(new FileInputStream(file));
- }catch(IOException e){
- System.out.println("There was a problem opening the file. " + e);
- }
- Agenda agenda = null;
- try{
- agenda = (Agenda)input.readObject();
- input.close();
- return agenda;
- }catch(Exception e){
- System.out.println("There was a issue reading this file: " + e);
- }
- }
- return null;
- }
- }
|