Skip to content

Commit

Permalink
Make sure that the output file is writable in the specified path. Als…
Browse files Browse the repository at this point in the history
…o make sure to close the stream.
  • Loading branch information
Atsushi Eno committed Mar 7, 2012
1 parent 2e0544c commit 6b18c26
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Start.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ public static void main (String[] args)
System.err.println (usage);
System.exit (1);
}
File dir = new File (out_path).getParentFile ();
if (!dir.exists ())
dir.mkdirs ();

JavaArchive jar = null;
try {
Expand Down Expand Up @@ -171,10 +174,12 @@ public static void main (String[] args)
TransformerFactory transformer_factory = TransformerFactory.newInstance ();
Transformer transformer = transformer_factory.newTransformer ();
transformer.setOutputProperty (OutputKeys.INDENT, "yes");
OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(out_path),"UTF-8");
FileOutputStream stream = new FileOutputStream(out_path);
OutputStreamWriter writer = new OutputStreamWriter(stream,"UTF-8");
StreamResult result = new StreamResult (writer);
DOMSource source = new DOMSource (doc);
transformer.transform (source, result);
writer.close ();
} catch (Exception e) {
System.err.println ("Couldn't format xml file - exception occurred:" + e.getMessage ());
}
Expand Down

0 comments on commit 6b18c26

Please sign in to comment.