• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Read a csv file in webservice

 
Greenhorn
Posts: 16
Hibernate Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 https://coderanch.com/how-to/java/AccessingFileFormats) instead of rolling your own CSV parser.
 
Vivek Pinto
Greenhorn
Posts: 16
Hibernate Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 https://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: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
Our first order of business must be this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic