title: read/write an object to file
body: <p>here is the code :
  my mission is to serialize an my object(Person) , save it in a file in android(privately), read the file later,(i will get a byte array), and deserialize the byta array. </p>
  
  <pre><code>       public void setup()
      {
  
             byte[] data = SerializationUtils.serialize(f);
  
  
               WriteByteToFile(data,filename); 
  
  
  
      }
  Person p =null ;
      public void draw()
      {
          File te = new File(filename);
           FileInputStream fin = null;
  
  
               try {
                  fin=new FileInputStream(te);
                  byte filecon[]=new byte[(int)te.length()];
                  fin.read(filecon);
                  String s = new String(filecon);
                  System.out.println("File content: " + s);
              } catch (FileNotFoundException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              } catch (IOException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
  
  
  
  
  
  
          text(p.a,150,150);
  
      }
  </code></pre>
  
  <p>and my function : </p>
  
  <pre><code>public void WriteByteToFile(byte[] mybytes, String filename){
  
          try {
  
          FileOutputStream FOS = openFileOutput(filename, MODE_PRIVATE);
          FOS.write(mybytes);
          FOS.close();
  
  
          } catch (FileNotFoundException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          } catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
          System.out.println("done");
  
  
  
  
  
  
  
  
  
      }
  </code></pre>
  
  <p>it is returning a filenotfoundexception .</p>
  
  <p>(i am new at this, so please be patient and understanding)</p>
  
  <p>EDIT ::this is how i am (trying to ) read, (for cerntainly) </p>
  
  <pre><code>ObjectInputStream input = null;
      String filename = "testFilemost.srl";
      try {
          input = new ObjectInputStream(new FileInputStream(new File(new File(getFilesDir(),"")+File.separator+filename)));
      } catch (StreamCorruptedException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      } catch (FileNotFoundException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
      try {
          Person myPersonObject = (Person) input.readObject();
          text(myPersonObject.a,150,150);
      } catch (OptionalDataException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      } catch (ClassNotFoundException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
      try {
          input.close();
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  </code></pre>
  
  <p>and for reading ::: </p>
  
  <pre><code>if(mousePressed)
  
  {
      Person myPersonObject = new Person();
      myPersonObject.a=432;
      String filename = "testFilemost.srl";
      ObjectOutput out = null;
  
      try {
          out = new ObjectOutputStream(new FileOutputStream(new File(getFilesDir(),"")+File.separator+filename));
      } catch (FileNotFoundException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
      try {
          out.writeObject(myPersonObject);
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
      try {
          out.close();
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  }
  </code></pre>