title: save a file in java
body: <p>I am trying to save a file in Java in this way:</p>
  
  <pre><code>PrintWriter output = null;
  int x=5, y = 6;
  try {               
      saveFile = new FileOutputStream("myFile.txt");
      save = new ObjectOutputStream(saveFile);    
      save.writeObject(x + y);
      save.close();                   
  } catch (FileNotFoundException e) 
  {               
      e.printStackTrace();
  } catch (IOException e) 
  {
      e.printStackTrace();
  }
  </code></pre>
  
  <p>and it is working but how can I save an object from another class because it is giving me an error when I try to do it.     </p>