Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Read a csv file in webservice  RSS feed

 
Vivek Pinto
Greenhorn
Posts: 16
Hibernate Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a requirement to build a webservice in which i have to read a CSV file from a location.Please not that WebService.
I have used something like this in local(the file is in my C: drive).

"
String csvFile = "C:/new.csv";
BufferedReader br = null;
br = new BufferedReader(new FileReader(csvFile));
while ((line = br.readLine()) != null)
{
String[] country = line.split(cvsSplitBy);


...blah blah..and the functionality goes...".

Can anybody tell me how to read a file in WebService like how to give path,how to get that file, reading path and etc.

any help is appreciated.
Thanks in Advance.
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you understand what a WebService is and for what purposes it is used for? You can of course instruct a WebService to parse a CSV file and for that you have different possibilities. You can call a method on the remote WebService that would parse the CSV file for you and for that you should tell the WebService where it can find the CSV file for parsing.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What difference do you see between reading a CSV file from within WS code, and reading a CSV file from any random piece of Java code?

I advise to use a CSV library (like one of the ones listed in http://www.coderanch.com/how-to/java/AccessingFileFormats) instead of rolling your own CSV parser.
 
Vivek Pinto
Greenhorn
Posts: 16
Hibernate Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:What difference do you see between reading a CSV file from within WS code, and reading a CSV file from any random piece of Java code?

I advise to use a CSV library (like one of the ones listed in http://www.coderanch.com/how-to/java/AccessingFileFormats) instead of rolling your own CSV parser.



Hi Harry,Dittmer,
Thank You so much for the reply!
I have written code(Working as expected) if the file is in my local file system.I may be silly with my questions!!
Now all i wanted to know is that how different it is if the file that i have to read is in some ftp location or some server.
Is it that i have just specify the location from where it should be read?And how it works?

Thank You
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That depends on how, exactly, the file is accessible. An FTP client is pretty easy to implement using the Apache Commons Net library. Some other protocol (SMB, WebDAV, HTTP, etc.) would require a different approach.
 
Vivek Pinto
Greenhorn
Posts: 16
Hibernate Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

I am able to complete the needed feature..

It was my fault while giving the path of the file.(Format of the path).

:-) :-)
Cheers..
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!