国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

推薦個上傳文件的javabean給大家

2019-11-18 13:42:54
字體:
供稿:網(wǎng)友

  推薦個上傳文件的javabean給大家

import java.io.*;
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;

public class transfer_multi {
public String[] sourcefile = new String[255];//源文件名
public String objectpath = "c:/";//目標(biāo)文件目錄
public String[] suffix = new String[255];//文件后綴名
public String[] objectfilename = new String[255];//目標(biāo)文件名
public ServletInputStream sis = null;//輸入流
public String[] description = new String[255];//描述狀態(tài)
public long size = 100*1024;//限制大小
PRivate int count = 0;//已傳輸文件數(shù)目
private byte[] b = new byte[4096];//字節(jié)流存放數(shù)組
private boolean sUCcessful = true;

public void setSourcefile(HttpServletRequest request) throws java.io.IOException{
sis = request.getInputStream();
int a = 0;
int k = 0;
String s = "";
while((a = sis.readLine(b,0,b.length)) != -1){
s = new String(b,0,a);
if((k = s.indexOf("filename=")) != -1){
s = s.substring(k+10);
k = s.indexOf(""");
s = s.substring(0,k);
sourcefile[count] = s;

k = s.lastIndexOf(".");
suffix[count] = s.substring(k+1);
System.out.println(suffix[count]);
if(canTransfer(count)) transferfile(count);
}
if(!successful) break;
}
}
public int getCount(){
return count;
}
public String[] getSourcefile(){
return sourcefile;
}

public void setObjectpath(String objectpath){
this.objectpath = objectpath;
}
public String getObjectpath(){
return objectpath;
}
private boolean canTransfer(int i){
suffix[i] = suffix[i].toLowerCase();
//這個是我用來傳圖片的,各位可以把后綴名改掉或者不要這個條件
if(sourcefile[i].equals("")(!suffix[i].equals("gif")&&!suffix[i].equals("jpg")&&!suffix[i].equals("jpeg"))) {description[i]="ERR suffix is wrong";return false;}
else return true;
}
private void transferfile(int i){
String x = Long.toString(new java.util.Date().getTime());
try{
objectfilename[i] = x+"."+suffix[i];
FileOutputStream out = new FileOutputStream(objectpath+objectfilename[i]);
int a = 0;
int k = 0;
long hastransfered = 0;//標(biāo)示已經(jīng)傳輸?shù)淖止?jié)數(shù)
String s = "";
while((a = sis.readLine(b,0,b.length)) != -1){
s = new String(b,0,a);
if((k = s.indexOf("Content-Type:")) != -1) break;
}
sis.readLine(b,0,b.length);
while((a = sis.readLine(b,0,b.length)) != -1){


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 云南省| 南部县| 浦城县| 沁源县| 都兰县| 扎赉特旗| 绥滨县| 观塘区| 湟中县| 忻城县| 湘潭市| 裕民县| 阳城县| 济宁市| 红原县| 施甸县| 新干县| 大港区| 和平县| 托克托县| 正宁县| 双城市| 固始县| 陆良县| 金山区| 远安县| 广灵县| 东城区| 两当县| 郴州市| 区。| 东海县| 玉林市| 临潭县| 图木舒克市| 阳朔县| 囊谦县| 和林格尔县| 永修县| 延长县| 泗阳县|