當前位置:首頁 » 文件管理 » ssh2圖片上傳

ssh2圖片上傳

發布時間: 2024-06-29 09:08:00

『壹』 SSH2中、從本地上傳文件是怎麼實現的

<s:form action="****" namespace="/***" enctype="multipart/form-data" theme="simple">
<input type="file" id="fi" name="myFile" style="height: 30"/>
<input type="submit" value="提交"/>
</s:form>
ACTION中:

// myFile屬性用來封裝上傳的文件
private File myFile;
// myFileContentType屬性用來封裝上傳文件的類型
private String myFileContentType;
// myFileFileName屬性用來封裝上傳文件的文件名
private String myFileFileName;
方法中:
//設置上傳文件目錄
String filePath=ServletActionContext.getServletContext().getRealPath("/****");
//基於myFile創建文件輸入流
InputStream is=new FileInputStream(myFile);
String a[] = myFileFileName.split("\\.");
System.out.println("上傳文件名:"+a[0]+"上傳文件類型:"+a[1]);
//設置目標文件
File toFile=new File(filePath,「可以自己取"+"."+a[1]);
//創建一個輸出流
OutputStream os=new FileOutputStream(toFile);
// OutputStream bos = new FileOutputStream(filePath);//建立一個上傳文件的輸出流
int bytesRead = 0;
byte[] buffer = new byte[8192];
while ( (bytesRead = is.read(buffer, 0, 8192)) != -1) {
os.write(buffer, 0, bytesRead);//將文件寫入伺服器
}

熱點內容
大地球源碼 發布:2025-07-04 08:10:29 瀏覽:163
棋牌手游源碼 發布:2025-07-04 08:10:18 瀏覽:816
為啥編程廣告 發布:2025-07-04 07:30:01 瀏覽:569
資料庫備機 發布:2025-07-04 07:30:00 瀏覽:532
靜態內部類java 發布:2025-07-04 07:25:45 瀏覽:234
玉林電信dns伺服器地址 發布:2025-07-04 07:17:34 瀏覽:437
用鏡像壓縮 發布:2025-07-04 07:17:31 瀏覽:635
lgg3如何設置鎖屏密碼 發布:2025-07-04 06:41:39 瀏覽:346
sqlserver2005命令 發布:2025-07-04 06:27:08 瀏覽:734
壓縮文件啥樣 發布:2025-07-04 06:21:42 瀏覽:300