title: How to write file to Android device from outside of activity?
body: <p>I have main activity where I'm creating a new object called fileSaver. I'm trying to sarialize object 'data' to file. FileSave has a method serialize() which creates file.</p>
  
  <pre><code>private String FILE_NAME = "file.dat";
  FileSaver fileSaver = new FileSaver();
  Data data = new Data();
  data.setEmail("aaa@bbb.com");
  fileSaver.serialize((Object) data,FILE_NAME);
  </code></pre>
  
  <p>The problem is that I can't create a file outside activity. When I try the same inside activity, it creates that file. I was experimenting with paths but without success. I know when the file is created from activity it is saved in /data/data/my_package_name/files but how to access that file from outside activity class?</p>
  
  <p>Class FileSaver:</p>
  
  <pre><code>public class FileSaver {
  
  public void serialize(Object objToSerialize,String fileName) {
  
      try {
          ObjectOutputStream out = new ObjectOutputStream(
                  new FileOutputStream(fileName));
          out.writeObject(objToSerialize);
          out.close();
          System.out.println("Object : " + objToSerialize.getClass()
                  + " serialized successfully");
      } catch (Exception ex) {
          System.out.println("Error Saving Object to File :"
                  + ex.getMessage());
          ex.printStackTrace();
      }
  }
  }
  </code></pre>
  
  <p>Thank you.</p>