I am created xml docs, but they are by default saving to the project folder in netbeans projects.
I have a file path that I need them to be saving to instead:
public static String XML_DIR = "c:/Users/ericrea/Desktop/413final";
Here is the code I have written so far, I tried using the f.renameto()
method, but it won't accept a string file location:
DOMSource source = new DOMSource(testDoc);
File f;
f=new File(emp.getId() + ".xml");
f.createNewFile();
PrintStream ps = new PrintStream(f);
StreamResult result = new StreamResult(ps);
TransformerFactory transformerFactory = TransformerFactory
.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.transform(source, result);
Try something like
File f = new File (XML_DIR, emp.getID() + ".xml");
That will match the
File(String parent, String child) Creates a new File instance from a parent pathname string and a child pathname string.
constructor
or
File f = new File (XML_DIR + emp.getID() + ".xml" );
That will use the
File(String pathname) Creates a new File instance by converting the given pathname string into an abstract
pathname. constructor for the File object. Either one should give you the result you're looking for.
More info on the File object here .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.