If you have used VB To Write File Upload components, it is very easy to use Java to Write File Upload JavaBean.
The following example is a simplified version.
Package yuanyifileup;
Import java. Io .*;
Import java. util .*;
Import javax. servlet .*;
Import javax. servlet. http .*;
Import javax. servlet. jsp. pagecontext;
Public class yuanyifileup
{
Private servletrequest request;
Private servletresponse response;
Private servletconfig config;
Servletinputstream data;
Int formsize;
File F1;
Fileoutputstream OS;
Datainputstream is;
String filename;
Byte [] B;
Byte T;
Boolean flag = false;
Public yuanyifileup ()
{}
Public void initialize (servletconfig config, httpservletrequest request, httpservletresponse response) throws ioexception
{
This. Request = request;
This. Response = response;
This. Config = config;
Data = request. getinputstream ();
Formsize = request. getcontentlength ();
}
Public void initialize (pagecontext) throws ioexception
{
Request = pagecontext. getrequest ();
Response = pagecontext. getresponse ();
Config = pagecontext. getservletconfig ();
Data = request. getinputstream ();
Formsize = request. getcontentlength ();
}
Public Boolean setfilename (string S)
{
Try
{
File F1 = new file (s );
OS = new fileoutputstream (F1 );
}
Catch (ioexception E)
{Return (false );}
Return (true );
}
Public void getbyte ()
{
Int I = 0;
Try
{
Is = new datainputstream (data );
B = new byte [formsize];
While (true)
{
Try
{
T = is. readbyte ();
B [I] = T;
I ++;
}
Catch (eofexception E)
{Break ;}
}
Is. Close ();}
Catch (ioexception E)
{}
}
Public Boolean save ()
{
Int I = 0, start1 = 0, start2 = 0;
String temp = "";
If (! Flag)
{
Getbyte ();
Flag = true;
}
Try
{
Temp = new string (B, "iso8859_1 ");
}
Catch (unsupportedencodingexception E)
{Return (false );}
Start1 = temp. indexof ("image /");
Temp = temp. substring (start1 );
Start1 = temp. indexof ("rnrn ");
Temp = temp. substring (start1 + 4 );
Start2 = temp. indexof ("; RN ");
If (start2! =-1)
{
Temp = temp. substring (0, start2 );
}
Try
{
Byte [] IMG = temp. getbytes ("iso8859_1 ");
For (I = 0; I {OS. Write (IMG [I]);}
OS. Close ();
}
Catch (ioexception E)
{Return (false );}
Return (true );
}
If you do not understand the E-mail: yymailbox@263.net.Bye
}