首页 > 学院 > 开发设计 > 正文

一个文本上传Bean的例子

2019-11-18 15:19:11
字体:
来源:转载
供稿:网友

  我在这个网站看见了几篇关于图片上传的bean,但是没有看见文本上传的bean 于是就写了个
上传文本的bean.此程序在tomcat4.1调试成功
package up;
import java.io.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletInputStream;
public class upjspBean {
int count=0;
int i=0;
String dataString=null;
String lastString=null;
public void doUpload(HttpServletRequest request) throws
IOException {
int indexof;
int n=0;
byte[]tmpdata=new byte[65536];
FileOutputStream fo=new FileOutputStream("a.txt");
BufferedOutputStream bo=new BufferedOutputStream(fo);
DataOutputStream file=new DataOutputStream(bo);
ServletInputStream si = request.getInputStream();
BufferedInputStream b i=new BufferedInputStream(si);
DataInputStream data=new DataInputStream(bi);
count=data.available();
try{while (true) {
tmpdata[count++] = data.readByte();
}}
catch(EOFException e) {data.close();}
dataString=new String(tmpdata,0,count);
indexof=dataString.indexOf("Content-Type:");
dataString=dataString.substring(indexof);
indexof=dataString.indexOf("");
dataString=dataString.substring(indexof+4);
indexof=dataString.indexOf("-----------------------------7d3");
dataString=dataString.substring(0,indexof-2);
tmpdata=dataString.getBytes();
i=tmpdata.length;
file.write(tmpdata,0,i);
file.close();
}
public int getCount() {
return(i);
}
}

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表