?
快捷搜索:  as  test  1111  test aNd 8=8  test++aNd+8=8  as++aNd+8=8  as aNd 8=8

百盛娛樂經典電子游戲:推薦個上傳文件的javabean給大家

?

作者:westsavage頒發光陰:2001-10-30 16:03:58

--------------------------------------------------------------------------------

作者: popeyelin

westsavage轉載cnjsp,假如作者不合意,我們將刪除。

import java.io.*;

import javax.servlet.Serv百盛娛樂經典電子游戲letInputStream;

import javax.servlet.http.HttpServletRequest;

public class transfer_multi {

public String[] sourcefile = new String[255];//源文件名

public String objectpath = "c:/";//目標文件目錄

public String[] suffix = new String[百盛娛樂經典電子游戲255];//文件后綴名

public String[] objectfilename = new String[255];//目標文件名

public ServletInputStream sis = null;//輸入流

public String[] description = new String[255];//描述狀態

public long size = 100*1024;//限定大年夜小

private int count = 0;//已傳輸文件數目

private byte[] b = new byte[4096];//字撙節寄放數組

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;//標示已經傳輸的字節數

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){

s = new String(b,0,a);

if((b[0]==45)&&(b[1]==45)&&(b[2]==45)&&(b[3]==45)&&(b[4]==45)) break;

out.wri百盛娛樂經典電子游戲te(b,0,a);

hastransfered+=a;

if(hastransfered>=size){

description[count] = "ERR The file "+sourcefile[count]+" is too large to transfer. The whole process is interrupted.";

successful = false;

break;

}

}

if(successful) description[count] = "Right The file "+sourcefile[count]+" has been transfered successfully.";

++count;

out.close();

if(!successful){

sis.close();

File tmp = new File(objectpath+objectfilename[count-1]);

tmp.delete();

}

}

catch(IOException ioe){

description[i]=ioe.toString();

}

}

public transfer_multi(){

//可以在構建器里面構建辦事器上傳目錄,也可以在javabea百盛娛樂經典電子游戲n調用的時刻自己構建

setObjectpath("/home/www/jspvhost4/web/popeyelin/images/");

}

}

免責聲明:以上內容源自網絡,版權歸原作者所有,如有侵犯您的原創版權請告知,我們將盡快刪除相關內容。

您可能還會對下面的文章感興趣:

河北十一选五开奖的 广西快乐双彩开奖结 排列三今天开奖结果 麻将棋牌辅助作弊器 小泽玛利亚 高清无码BT 爵士vs黄蜂 中国男足世界杯比分 下载内蒙古全民麻将 股票行情今天大盘直播 江苏快三 信弘配资 广东十一选五结果一 青海11选5开奖结 明星上海麻将作弊视频 日本一本道百度视频 太原红灯区在哪 老快3