課程
/后端開(kāi)發(fā)
/Java
/Java中的文件上傳下載
?手動(dòng)創(chuàng)建:temp這個(gè)文件夾 完整路徑為: D:\temp\temp.txt
2017-01-07
源自:Java中的文件上傳下載 2-3
正在回答
InputStream fileSource ?= request.getInputStream();
//得到服務(wù)器的根路徑
String rootPath = request.getRealPath("/");
//指定文件存放路徑
String realPath = rootPath + "/" + "upload";
//定義文件存放的目錄,注意 目錄也是文件
File file = new File(realPath);
//如果目錄不存在
if (!file.isDirectory()) {
//創(chuàng)建文件上傳目錄
file.mkdirs();
}
File newFile = new File(realPath + "/" + "tempFile");
//向newFile文件中寫入數(shù)據(jù)
//文件存放在Tomcat中項(xiàng)目的根目錄下的upload文件夾中
FileOutputStream outputStream ?= new FileOutputStream(newFile);
byte[] b = new byte[1024];
int n;
while((n=fileSource.read(b))!=-1){
outputStream.write(b,0,n);
outputStream.close();
fileSource.close();
System.out.println("Post..");
辰塵
你解決了嗎拒絕訪問(wèn)?
手動(dòng)創(chuàng)建:temp這個(gè)文件夾 完整路徑為: D:\temp\temp.txt
舉報(bào)
由簡(jiǎn)入深,輕松實(shí)現(xiàn)文件上傳下載功能及相關(guān)框架的使用
1 回答路徑為什么拒絕訪問(wèn)?
3 回答文件夾拒絕訪問(wèn)時(shí)什么問(wèn)題啊
2 回答老師,我的文件夾出現(xiàn)拒絕訪問(wèn)
2 回答請(qǐng)問(wèn)老師我用smartupload實(shí)現(xiàn)下載的時(shí)候,報(bào)文件拒絕訪問(wèn)的錯(cuò)誤怎么解決,下載地址沒(méi)有錯(cuò)
1 回答啟動(dòng)時(shí)報(bào)錯(cuò),頁(yè)面訪問(wèn)不了index,jsp
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2017-04-27
InputStream fileSource ?= request.getInputStream();
//得到服務(wù)器的根路徑
String rootPath = request.getRealPath("/");
//指定文件存放路徑
String realPath = rootPath + "/" + "upload";
//定義文件存放的目錄,注意 目錄也是文件
File file = new File(realPath);
//如果目錄不存在
if (!file.isDirectory()) {
//創(chuàng)建文件上傳目錄
file.mkdirs();
}
File newFile = new File(realPath + "/" + "tempFile");
//向newFile文件中寫入數(shù)據(jù)
//文件存放在Tomcat中項(xiàng)目的根目錄下的upload文件夾中
FileOutputStream outputStream ?= new FileOutputStream(newFile);
byte[] b = new byte[1024];
int n;
while((n=fileSource.read(b))!=-1){
outputStream.write(b,0,n);
}
outputStream.close();
fileSource.close();
System.out.println("Post..");
2017-03-16
你解決了嗎拒絕訪問(wèn)?
2017-01-07
手動(dòng)創(chuàng)建:temp這個(gè)文件夾 完整路徑為: D:\temp\temp.txt