wood burning stoves 2.0*
The moose likes EJB and other Java EE Technologies and the fly likes referencing csv/text file for Java EE web application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "referencing csv/text file for Java EE web application" Watch "referencing csv/text file for Java EE web application" New topic
Author

referencing csv/text file for Java EE web application

Sammy Robert
Greenhorn

Joined: Oct 14, 2011
Posts: 5
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

Joined: Jul 13, 2010
Posts: 610

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!


OCP Java SE 6 Programmer, OCM Java SE 6 Developer, OCE Java EE 6 JSPSD, OCE Java EE 6 EJBD, OCE Java EE 6 JPAD, Spring 3.0 Core Professional.
Sammy Robert
Greenhorn

Joined: Oct 14, 2011
Posts: 5
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

Joined: Oct 14, 2011
Posts: 5
never mind. I got it to work. Here is what I did -



Thanks for the pointers
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: referencing csv/text file for Java EE web application