Hi,
You can have an HTML file with the input field for file like.
<input type=file name=file>
Using this input field u can allow the user to browse for the file to be
uploaded.
Once the file is selected submit the form to the servlet.
At the servlet use the request object to read the file as a stream and write
it any where u want.
At the servlet in the doPost() method use the following code.
BuffereReader br=new BufferedReader(new
InputStreamReader(request.getInputStream()));
String strTemp="";
while((strTemp=br.readLine())!=null)    {
        System.out.println(strTemp);
}

You can either read the contents of the file as bytes(for binary files) or
string(for text files) and write it to some file using fileoutput stream.
You can get the name of the file uploaded by using
request.getParameter("file");

-regards
#########################
Chetan P Hiremath(Software Engineer)
Nuntius Systems(India) Pvt Ltd, Bangalore.
http://www.india.nuntius.com
080-658 0484


> -----Original Message-----
> From: Geert Van Landeghem [SMTP:[EMAIL PROTECTED]]
> Sent: Monday, February 11, 2002 1:37 PM
> To:   [EMAIL PROTECTED]
> Subject:      servlet file upload?
>
> How do you upload a file with http and servlets? Does anybody have
> an example of this? I have already written a servlet that let's you
> browse the directory structure of the webserver and let's you
> download files if wanted. Now I want to build the upload feature...
>
> Thanks in advance,
>
>
>
> Geert Van Landeghem
> Reynders Etiketten N.V
> *   +32-(0)3/460.32.81
> * +32-(0)3/455.18.83
> M      +32-0477/75.95.33
> *   [EMAIL PROTECTED]
>
> __________________________________________________________________________
> _
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
> body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to