0

I was stuck here for last all night. In my project, I need to read the xml file and use the relative path.(like String location = "AuctionItem.xml"; File f = new File(location); below)

String location = "AuctionItem.xml";
File f = new File(location);
Document doc = builder.parse(f);

It worked well if I used a java text file.

public static void main(String[] arg){
    File f = new File("AuctionItem.xml");
    System.out.println(AuctionItemsControl.getValue().size());
// here the method below is call the function which has the relative path.
}

However, when I used them in my project by jsp, it gave a error : java.io.FileNotFoundException:/Users/XXX/Documents/Tool/web/eclipse/Eclipse.app/Contents/MacOS/AuctionItem.xml (No such file or directory)

  • does the file really exist in directory `/Users/XXX/Documents/Tool/web/eclipse/Eclipse.app/Contents/MacOS`? – Baby Apr 10 '15 at 01:24
  • no, I use the relative path and the file exists in the project which is : /Users/XXX/Dropbox/Mu/Study/UNSW/Semester4/comp9321/workplace/Assignment01/AuctionItem.xml – user3123253 Apr 10 '15 at 01:26
  • then change your location as `String location = "//Users//XXX//Dropbox/Mu//Study//UNSW//Semester4//comp9321//workplace//Assignment01//Aucti‌​onItem.xml"` – Baby Apr 10 '15 at 01:33
  • Yes, I tried that and worked. But I need to use relative path here. It's a homework. – user3123253 Apr 10 '15 at 01:37
  • define your [relative path](http://stackoverflow.com/questions/14209085/how-to-define-a-relative-path-in-java) . If you didnt specify the path, it will point to project directory by default – Baby Apr 10 '15 at 01:44

0 Answers0