Problem serializing and deserializing ArrayList

前端 未结 1 588
无人及你
无人及你 2020-12-18 13:34

Anytime I try to serialize a file I get the error: FileNotFound. Not sure why. Here is my FileHelper code:

package org.stocktwits.helper;

import java.io.Byt         


        
相关标签:
1条回答
  • 2020-12-18 14:17
    private void serializeQuotes(){
            FileOutputStream fos;
            try {
                fos = openFileOutput(Constants.FILENAME, Context.MODE_PRIVATE);
                ObjectOutputStream oos = new ObjectOutputStream(fos);
                oos.writeObject(quotes); 
                oos.close();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }catch(IOException e){
                e.printStackTrace();
            }
        }
    
        @SuppressWarnings("unchecked")
        private void deserializeQuotes(){
            try{
                FileInputStream fis = openFileInput(Constants.FILENAME);
                ObjectInputStream ois = new ObjectInputStream(fis);
                quotes = (ArrayList<Quote>) ois.readObject();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }catch(IOException e){
                e.printStackTrace();
            }catch(ClassNotFoundException e){
                e.printStackTrace();
            }
        }
    
    0 讨论(0)
提交回复
热议问题