The Artima Developer Community
Sponsored Link

Java Answers Forum
Reading a CSV file from client on Server

1 reply on 1 page. Most recent reply: Oct 15, 2007 11:26 AM by Doug Gunnoe

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Mado Kumar

Posts: 1
Nickname: mado16
Registered: Oct, 2007

Reading a CSV file from client on Server Posted: Oct 12, 2007 2:09 AM
Reply to this message Reply
Advertisement
Hi,

I am trying to reading a CSV file and saving the in database. This part of the code is done. When I am reading the file from server it is working. But when I am trying to read the file from client machine it is not reading the file and throwing FileNotFoundException. This is how I have try this :-
try {
            File file = new File(filePath);
            if(file.exists()) {
                System.out.println("File exists at the specified location");
            }else {
                System.out.println("Not able to find the file");
            }
            System.out.println("Successfully get the file");
            URL serverURL = new URL(SERVER_URL);
            System.out.println("Successfully get the URL");
            HttpURLConnection serverCon = (HttpURLConnection) serverURL.openConnection();
            System.out.println("Successfully opened the connection");
            // setup connection
            serverCon.setDoInput(true);
            serverCon.setDoOutput(true);
            serverCon.setUseCaches(false);
            serverCon.setRequestProperty(FILENAME_HEADER, fileName); // send the filename through HTTP header
            System.out.println("Successfully set the header");
            // POST the file's bytes to the connections OutputStream
            OutputStream toServer = serverCon.getOutputStream();
            System.out.println("Successfully get the servlet output Stream");
            FileInputStream fromFile = new FileInputStream(file);
            System.out.println("Hopefully! this line will not print");//Here it is throwing exception

Can anyone help in acheiving this task. I have already tried it using MultipartRequest but later I found that my HTML encoding is not supporting multipart/form-data.

thanks,

mado


Doug Gunnoe

Posts: 22
Nickname: dgun
Registered: May, 2007

Re: Reading a CSV file from client on Server Posted: Oct 15, 2007 11:26 AM
Reply to this message Reply
SO this works?

File file = new File(filePath);
            if(file.exists()) {
                System.out.println("File exists at the specified location");


Are you sure the above works? Is there a file by the same name in the same directory on the server?

But the following does not work?

FileInputStream fromFile = new FileInputStream(file);


I don't think a servlet can open a stream to a file on a client machine.

I found this: http://www.jguru.com/faq/view.jsp?EID=1045509

Unless this is an applet? If this is an applet, it cannot open a stream to a file on a client machine unless it is a trusted applet.

http://www.developer.com/java/data/article.php/3303561

Hope that helps. Good luck.

Flat View: This topic has 1 reply on 1 page
Topic: Reading a CSV file from client on Server Previous Topic   Next Topic Topic: checkbox listener

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use