my dog learned polymorphism*
The moose likes Servlets and the fly likes Reading file from client machine Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Reading file from client machine" Watch "Reading file from client machine" New topic
Author

Reading file from client machine

sam jose
Greenhorn

Joined: Jul 02, 2006
Posts: 6
How can my Web application read a .txt file from the client machine and execute some DML statements to update the Database ?
Any comment is appreciated.
Thanks.
pawank gupta
Ranch Hand

Joined: Jun 07, 2006
Posts: 34
u can send ur file as attachement with ur post request(multipart) to server, from wher u can read it

or

make a url connection and read the file at server end
Manish Sridharan
Ranch Hand

Joined: Jul 19, 2005
Posts: 64
TRY USING APACHE FILE UPLAOD TAG TO UPLOAD THE ATTACHMENTS. IT IS EASY TO USE..

THANKS


GAURAV NIGAM


Manish S.
sam jose
Greenhorn

Joined: Jul 02, 2006
Posts: 6
Hi,

I think sending file as 'attachment (multipart)'/'apache file upload' will create a physical presence of the file in the server.
Correct me if I am wrong.
Can I read the file without creating a physical presence of the file in the server?

Thanks for the prompt reply
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by samjose samjose:
I think sending file as 'attachment (multipart)'/'apache file upload' will create a physical presence of the file in the server.
Correct me if I am wrong.
Can I read the file without creating a physical presence of the file in the server?


No. Not necessarily. We can read the file without writing it back to somewhere. It would be persisted if you want it to like write it somewhere on the server.

By the way, getting update statement from the file, which resides on the client machine . Any particular reasons?
pawank gupta
Ranch Hand

Joined: Jun 07, 2006
Posts: 34
no u cant read file without saving it u programmetically save and delete it
sam jose
Greenhorn

Joined: Jul 02, 2006
Posts: 6
Hi Adeel,

Is it really possible, with out storing the file ?
Can you give the details.

I request comments from Ranchers.

Thanks.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

"samjose samjose",
Welcome to the Ranch!

We're a friendly bunch, but we take our display names very seriously.

We require display names to be two words: your first name, a space, then your last name. Fictitious names are not allowed.

Please edit your profile and fix your display name since accounts with invalid display names get deleted.

thanks
Dave.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by pawank gupta:
no u cant read file without saving it u programmetically save and delete it


Agreed. If you are particularly talking about Commons Fileupload. Otherwise we can implement it on our own.

Never tried but it sounds like possible to use getInputStream()/getOutputStream in this case, using Commons.
[ July 04, 2006: Message edited by: Adeel Ansari ]
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Yes Indeed.

From Fileupload Using Guide

"With uploaded files, you generally will not want to access them via memory, unless they are small, or unless you have no other alternative. Rather, you will want to process the content as a stream, or write the entire file to its ultimate location. FileUpload provides simple means of accomplishing both of these.


Note that, in the default implementation of FileUpload, write() will attempt to rename the file to the specified destination, if the data is already in a temporary file. Actually copying the data is only done if the the rename fails, for some reason, or if the data was in memory.

If you do need to access the uploaded data in memory, you need simply call the get() method to obtain the data as an array of bytes.

[ July 03, 2006: Message edited by: Adeel Ansari ]
sam jose
Greenhorn

Joined: Jul 02, 2006
Posts: 6
Thanks to you all.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

pawank gupta,
Welcome to JavaRanch!

In an effort to help you get the most from our forums, we've compiled a
list of tips for asking questions here. You can find the list in our
FAQ section here.

In particular please see: UseRealWords

Abbreviations such as "u" or "ur" in place of "you" and "you are"
or "you're" confound language translation software making it hard
for our non-English speaking members to read your posts.

Again, welcome to JavaRanch and good luck with your question.
-Ben


As to your comment.
Jakarta's commons/fileupload will allow you to read the uploaded file into memory and work with it without having to save it to disk.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reading file from client machine
 
Similar Threads
FileSystemObject
Plz help me...
Accessing client side folder structure
Servlet to read XML tags from Client
java.io.FileNotFoundException