aspose file tools*
The moose likes JSP and the fly likes Reading and manipulating file content on client machine 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 » JSP
Bookmark "Reading and manipulating file content on client machine" Watch "Reading and manipulating file content on client machine" New topic
Author

Reading and manipulating file content on client machine

muktesh tripathi
Ranch Hand

Joined: Nov 20, 2007
Posts: 30
I have a desktop application that prompts a user for file names and then using regex manipulates and displays the sorted/selected data/lines..

I want to do the same thing in web app... Ask user for file name/names and then manipulate data using some POJO class and then display the result....

How can i achieve that if possible..
1.Is it possible to directly access file on client machine?
2.If not, than can I read only line by line from selected file and then direct that input for
manipulation to some other class(POJO) and then display result using JSP..
Please Help...

Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30764
    
156

Muktesh,
A web application can upload a single file if the user browses to it. Everything else is a security issue and forbidden by the browser.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9305
    
  17

I don't think that you can access files on the client machine. You will have to upload the file on the server and then manipulate the file. I don't think that applets can help either cause they run in the sandbox which will not allow you to access client files for security reason. So IMHO, file uploading is the solution...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
muktesh tripathi
Ranch Hand

Joined: Nov 20, 2007
Posts: 30
Thanks the answers confirmed my fear...

If I go for it ..is there a way to get a user select multiple files(3 or 4) from a particular directory on his machine???

Or as I fear I will have to ask him four times for four files in same directory......This will surely kill my intentions of making my programme web based....
Thanks in advance
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Consider an applet or webstart application.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9305
    
  17

Well I don't think you can upload multiple files at once. At least not through file upload box. For that you will have to do some advance work. For example orkut allows you to upload multiple photos. That is a flash which let's you select multiple files. Similarly I think there must be more ways of doing this. But I don't know any of them so let's see if anyone has some idea about this...
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61433
    
  67

Ankit Garg wrote:Well I don't think you can upload multiple files at once.

Yes, you can. Multiple files can be uploaded in a single request. But each file must be individually selected via a file control input element.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9305
    
  17

Bear Bibeault wrote:Yes, you can. Multiple files can be uploaded in a single request. But each file must be individually selected via a file control input element.


Yes I know that. But then he will have to ask the client to choose the files multiple times. That's what he doesn't want...
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Ankit Garg wrote:
Yes I know that. But then he will have to ask the client to choose the files multiple times. That's what he doesn't want...


That's your only option if you want a pure HTML/Javascript front end.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
muktesh tripathi
Ranch Hand

Joined: Nov 20, 2007
Posts: 30
Thanks all...
I have also seen those multiple file select option in geicites.com upload... but its a great pain...
Webstart is the only option I suppose...Never tried it....But this might be a good oppurtunity..
Thanks again
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42286
    
  64
muktesh tripathi wrote:I have also seen those multiple file select option in geicites.com upload... but its a great pain...
Webstart is the only option I suppose...

More important than the pain you may feel is the pain your users may feel. I can't imagine a situation where selecting 4 files sequentially is more painful than the combined pain of your users having to live with a WebStart application, and you having to support it (and them). I regret to say this, but client-side Java in a browser is painful, for the most part.


Ping & DNS - my free Android networking tools app
muktesh tripathi
Ranch Hand

Joined: Nov 20, 2007
Posts: 30
What I meant was that I require particular kinds of files to be manipulated...These files are generated as some kind of logs or from input stream from some port connected to .....they are generated 4 times a day in user specified folder..
now the user gives me path to those files and I give him output based on the files content after manipulation....
suppose the file is in c:\A\B\D\E\Folder... so to select the four files the user has to follow full path four times ....

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42286
    
  64
Could you make sure that the file/directory structure is well-known in advance (and is not changing), so that you can code that knowledge into the application? That way, the user only has to select the root directory wherein all files/subdirectories are located.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61433
    
  67

muktesh tripathi wrote:so to select the four files the user has to follow full path four times ....

In most browsers, the file upload dialog will remember the most recent folder.
muktesh tripathi
Ranch Hand

Joined: Nov 20, 2007
Posts: 30
"
In most browsers, the file upload dialog will remember the most recent folder."



I think this will be of great help....Is there any way of specifying the default path for file upload directory on the client side..refer quoted text below

"Could you make sure that the file/directory structure is well-known in advance (and is not changing), so that you can code that knowledge into the application? That way, the user only has to select the root directory wherein all files/subdirectories are located."

Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
No, that´s not possible with HTML.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reading and manipulating file content on client machine