• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to read Files in Eclipse , getting FileNotFound exception  RSS feed

 
Mahtab Alam
Ranch Hand
Posts: 391
1
Java MySQL Database PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a Dynamic Web Project , and in one of the Class method I am reading an xml file.

The problem is until now I am giving the absolute path of file on my system

File quizFile=new File("C:\\Users\\Mahtab\\Quizzes\\quiz1.xml");

I understand its bad way , so I want to put these xml files in my eclipse project itself.

So I created a new folder called quizzes under src and put all those xml files in quizzes folder.

I am trying to read the file , I tried

File quizFile=new File("quizzes\\quiz1.xml");

File quizFile=new File("quizzes\quiz1.xml");

But getting FileNotFondException , how can I refer to these files.What path should I point to.
 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To get the file inside your package you can use:



If you want to use new File() then you may want to use the getResource() method (returns a URL) rather than getResourceAsStream()
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!