Just use new File("name")
that creates a file in the current working directory. With new File("../name")
you create a file in the parent directory. You then need to wrap the file in a FileOutputStream
.
But I would consinder using JAXB.unmarshal(file, clazz)
for reading and JAXB.marshal(object, file)
for writing. Just delete the old file before you write the new one. I never had troubles with updating resp. overwriting.
Here is how I did it, I removed the exception handling and logging. Pretty concise and generic, too.
public static <T> void writeXml(T obj, File f)
{
JAXB.marshal(obj, f);
}