java.io.IOException: Permission denied
807605Aug 20 2007 — edited Aug 21 2007Hi All,
Having a bit of trouble out of a school project. I need to save information to an XML file and read from it and put those values into fields. Writing to the file is no big deal, however I get a Permission Denied error when I attempt to read the data back in. My code is attached:
private boolean readFile(String filename) throws IOException{
try {
XPathFactory factory=XPathFactory.newInstance();
XPath xPath=factory.newXPath();
//File xmlDocument = new File(filename);
System.out.println("Here");
FileInputStream in = new FileInputStream(filename);
System.out.println("Here2");
InputSource inputSource=new InputSource(in);
System.out.println("Here3");
String xmlShape = xPath.evaluate("/Volume_Calculator/Shape",inputSource);
String xmlLength = xPath.evaluate("/Volume_Calculator/Length",inputSource);
String xmlWidth = xPath.evaluate("/Volume_Calculator/Width",inputSource);
String xmlAvgDepth = xPath.evaluate("/Volume_Calculator/Average_Depth",inputSource);
String xmlVolume = xPath.evaluate("/Volume_Calculator/Volume",inputSource);
String xmlCustName = xPath.evaluate("/Volume_Calculator/Customer_Name",inputSource);
String xmlAddress1 = xPath.evaluate("/Volume_Calculator/Address1",inputSource);
String xmlAddress2 = xPath.evaluate("/Volume_Calculator/Address2",inputSource);
String xmlCity = xPath.evaluate("/Volume_Calculator/City",inputSource);
String xmlState = xPath.evaluate("/Volume_Calculator/State",inputSource);
String xmlZip = xPath.evaluate("/Volume_Calculator/Zip",inputSource);
String xmlPhone = xPath.evaluate("/Volume_Calculator/Phone",inputSource);
String xmlEmail = xPath.evaluate("/Volume_Calculator/Email",inputSource);
String xmlSalesPerson = xPath.evaluate("/Volume_Calculator/Sales_Person",inputSource);
String xmlOrderNo = xPath.evaluate("/Volume_Calculator/Order_No",inputSource);
String xmlDate = xPath.evaluate("/Volume_Calculator/Date",inputSource);
txtLength.setText(xmlLength);
txtWidth.setText(xmlWidth);
txtAvgDepth.setText(xmlAvgDepth);
txtVolume.setText(xmlVolume);
txtCustName.setText(xmlCustName);
txtAddress1.setText(xmlAddress1);
txtAddress2.setText(xmlAddress2);
txtCity.setText(xmlCity);
txtZip.setText(xmlZip);
txtPhone.setText(xmlPhone);
txtEmail.setText(xmlEmail);
txtSalesPerson.setText(xmlSalesPerson);
txtOrderno.setText(xmlOrderNo);
txtOrderDate.setText(xmlDate);
in.close();
}
catch (Throwable t) {
t.printStackTrace ();
}
return true;
}
My XML document is flat with no repeating nodes.
Any help is greatly appreciated, thank you.
- James