• 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:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

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()
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!