Week 5 Lab - StockIO.java - Programmer Class Name...

This preview shows page 1 - 2 out of 2 pages.

/** Programmer: * Class Name: StockIO.java* Purpose: Handles writing to and reading from files.*/package lab5;import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.File;import java.io.FileReader;import java.io.FileWriter;import java.io.IOException;import java.util.ArrayList;import java.util.StringTokenizer;import javax.swing.JOptionPane;public class StockIO {public void saveData(ArrayList<Stock> al, File file){try{ //save data to file by opening, writing, and closingBufferedWriter outfile = new BufferedWriter(new FileWriter (file));for (Stock s: al){outfile.write(s.toFile());outfile.newLine();}outfile.close();}catch (IOException ex){ //print error so user knows what is wrongJOptionPane.showMessageDialog(null, "Could not save data to file.\n" + ex.toString(), "Error", JOptionPane.ERROR_MESSAGE);return;}}public ArrayList<Stock> getData(File file){try{BufferedReader inbuffer = new BufferedReader(new

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture