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

熱點內容
視頻上傳網站那些 發布:2024-07-01 12:09:05 瀏覽:974
手機怎麼設文件夾 發布:2024-07-01 12:06:18 瀏覽:200
androidchm 發布:2024-07-01 11:51:11 瀏覽:242
python語言類型 發布:2024-07-01 11:50:35 瀏覽:858
編程題匯總 發布:2024-07-01 11:50:34 瀏覽:849
如何取消iphone確認密碼 發布:2024-07-01 10:59:48 瀏覽:510
包餃子多了如何存儲 發布:2024-07-01 10:58:29 瀏覽:833
為什麼安卓沒有孤膽車神 發布:2024-07-01 10:52:49 瀏覽:325
戰爭雷霆為什麼不能連接伺服器 發布:2024-07-01 10:52:49 瀏覽:208
python深拷貝 發布:2024-07-01 10:48:25 瀏覽:696