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 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 ("\ r \ n ");
Temp = temp. substring (start1 + 4 );
Start2 = temp. indexOf ("; \ r \ n ");
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
}