Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

referencing csv/text file for Java EE web application

 
Sammy Robert
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have developed an application which parses a csv file and uploads the data into MySQL DB. I'm able to achieve this however while parsing the CSV I'm providing the absolute path, something like "c:\data\file.csv".
Can you please help me about how to provide relative path for the file. I have copied the csv file into my project directory under src>data. But unable to reference it to that location.



tried using .getabsolutepath("."), however it points me to the GlassFish server folder in C: and there I can't find any files /folder which has file.csv.
I'm using NetBeans and glassfish server to deploy application.

Appreciate any help.
Thanks
 
Piotr Nowicki
Ranch Hand
Posts: 611
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you can deploy this file to the place where it can be located by the classloader than you can use:

You could also use the getResourceAsStream method to get InputStream object instead of URL. There is also another way of obtaining the resource from classloader (using Class object or the System object). More about the differences between those can be found here:

http://www.javaworld.com/javaworld/javaqa/2003-06/01-qa-0606-load.html

Frankly, I think that the flat-file access in the EJB's is a specification violation, so if you're using EJB's than treat this as a warning :-)

HTH.

Cheers!
 
Sammy Robert
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply Pedro Kowalski.
When you say
If you can deploy this file to the place where it can be located by the classloader
, you mean if I can place the text/csv file in the WEB-INF/classes/ folder I can reference that file, correct?
I tried using the way you had mentioned however while passing the value to open the file, should it be done this way: -



Thank You.
 
Sammy Robert
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
never mind. I got it to work. Here is what I did -



Thanks for the pointers
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic