• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

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

 
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.
 
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!