title: Save XML file with XStream
body: <p>I use <code>XStream</code> to write an object in a <code>xml file</code>. <br />
  Then I deserializing the file again to use the objects. <br />
  My Problem is, that after I close my program, the xml "file" is gone. So how can I save this xml file to a specific directory? I already tried <code>FileOutputStream</code> but it doesn't work... I also google it, but found not the right solution for me...</p>
  
  <p>Method <strong>savePerson</strong></p>
  
  <pre><code>public void savePerson(String uNummer, Person person) {
      System.out.println("save person");
      try{            
          xml = xstream.toXML(person);
  
      }catch (Exception e){
          System.err.println("Error in XML Write: " + e.getMessage());
      }
  }
  </code></pre>
  
  <p>And the Method <strong>readPerson</strong></p>
  
  <pre><code>public Person readPerson(String uNummer) {
      System.out.println("read person");
       Person person = new Person();
      try{
          person = (Person) xstream.fromXML(file_path + uNummer + ".xml");       
      }catch(Exception e){
          System.err.println("Error in XML Read: " + e.getMessage());
      }
      return person;
  }
  </code></pre>
  
  <p><strong>Directory</strong>: <code>\\releasearea\ToolReleaseArea\PersistenceSave</code></p>
  
  <p><strong>EDIT</strong> <br />
  <strong>Correct Code</strong>: (by <strong>ppeterka</strong>)</p>
  
  <pre><code>public void savePerson(String uNummer, Person person) {
      System.out.println("save person XML");
      FileOutputStream fos = null;
      try{            
          xml = xstream.toXML(person);
          fos = new FileOutputStream(file_path + uNummer + ".xml");
          fos.write("&lt;?xml version=\"1.0\"?&gt;".getBytes("UTF-8"));
          byte[] bytes = xml.getBytes("UTF-8");
          fos.write(bytes);
  
      }catch (Exception e){
          System.err.println("Error in XML Write: " + e.getMessage());
      }
      finally{
          if(fos != null){
              try{
                  fos.close();
              }catch (IOException e) {
                  e.printStackTrace();
              }
          }
      }
  }
  </code></pre>