如果你曾用VB編寫文件上傳的組件的話
下面的例子只是一個簡版
package yuanyifileup;
import java
import java
import javax
import javax
import javax
public class yuanyifileup
{
private ServletRequest request;
private ServletResponse response;
private ServletConfig config;
ServletInputStream DATA;
int FormSize;
File f
FileOutputStream os;
DataInputStream is;
String filename;
byte[] b;
byte t;
boolean flag=false;
public yuanyifileup()
{ }
public void initialize(ServletConfig config
{
this
this
this
DATA = request
FormSize=request
}
public void initialize(PageContext pageContext) throws IOException
{
request=pageContext
response=pageContext
config=pageContext
DATA = request
FormSize=request
}
public boolean setFilename(String s)
{
try
{
File f
os=new FileOutputStream(f
}
catch(IOException e)
{return(false);}
return(true);
}
public void getByte()
{
int i=
try
{
is=new DataInputStream(DATA);
b=new byte[FormSize];
while (true)
{
try
{
t=is
b[i]=t;
i++;
}
catch(EOFException e)
{ break;}
}
is
catch(IOException e)
{}
}
public boolean save()
{
int i=
String temp="";
if (!flag)
{
getByte();
flag=true;
}
try
{
temp=new String(b
}
catch(UnsupportedEncodingException e)
{return(false);}
start
temp=temp
start
temp=temp
start
if (start
{
temp=temp
}
try
{
byte[] img=temp
for (i=
{ os
os
}
catch(IOException e)
{return(false);}
return(true);
}
如果有不明白的發E
}
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/20183.html