當前位置:首頁 » 文件管理 » 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);//將文件寫入伺服器
}

熱點內容
樂視1怎麼取消密碼是多少 發布:2025-10-18 18:26:16 瀏覽:37
逆鱗壓縮 發布:2025-10-18 18:15:57 瀏覽:765
數據存儲器ds216 發布:2025-10-18 18:03:55 瀏覽:980
手機游戲安卓源碼 發布:2025-10-18 18:02:05 瀏覽:861
mssql資料庫伺服器 發布:2025-10-18 17:49:27 瀏覽:15
android凱立德 發布:2025-10-18 17:36:41 瀏覽:463
安卓手機如何互轉 發布:2025-10-18 17:29:12 瀏覽:874
python批處理腳本 發布:2025-10-18 17:24:39 瀏覽:843
android無法接收廣播 發布:2025-10-18 17:18:39 瀏覽:378
java上海培訓 發布:2025-10-18 17:12:29 瀏覽:691