當前位置:首頁 » 文件管理 » 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-04-23 00:58:54 瀏覽:721
大學編程課程 發布:2025-04-23 00:48:55 瀏覽:469
伺服器的內網ip有什麼用 發布:2025-04-23 00:46:40 瀏覽:958
誅仙3需要什麼配置 發布:2025-04-23 00:29:49 瀏覽:665
什麼是編譯錯誤參數不可選 發布:2025-04-23 00:23:06 瀏覽:520
libx264編譯 發布:2025-04-23 00:13:37 瀏覽:222
access的web資料庫 發布:2025-04-23 00:08:29 瀏覽:46
安卓上面的谷歌搜索框怎麼去除 發布:2025-04-23 00:07:27 瀏覽:171
c判斷文件夾是否存在 發布:2025-04-22 23:56:36 瀏覽:943
精確測演算法 發布:2025-04-22 23:54:09 瀏覽:287