일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
- 분기날짜
- 강화 프로방스
- Windows10
- cisco vpn
- 핸드폰 찾기
- 로니세라
- 코로나백신 부작용
- 코로나백신 어지러움
- 윈도우10 vpn
- 크롬 타임아웃
- 응용 프로그램 내 구입
- 노리로또
- takanaru
- windows10 cisco vpn
- 코로나백신
- windows10 크롬
- 10원단위 올림
- 크롬 인터넷연결
- 타카마루
- 신주쿠맛집
- 크롬 인너넷연결 안됨
- 성수족발
- 안드로이드폰 위치
- 10 올림
- 오라클
- 랍스터 찜
- 화이자백신
- 신주쿠 로컬식당
- 코로나백신이상증상
- 코로나백신 갈증
- Today
- Total
이거 맘대로 되는 세상이 아니구만...
[JAVA] cos.jar을 이용한 파일업로드 다운로드 입니다. 본문
이런한 자료는 많은데 제가 직접 조금 수정하고 만들었다는데 의의를 두고있어여 ^^ㅋ
1. File Upload
MultipartRequest multi = null;
String savepath = request.getRealPath("/") + "WebContent/StyleUpload";
int limitSize = 15 * 1024 * 1024;
try {
multi = new MultipartRequest(request, savepath, limitSize, "euc-kr",
new DefaultFileRenamePolicy());
task = multi.getParameter("task");
String styleNo = multi.getParameter("styleNo");
String contents = multi.getParameter("contents");
String attachFile = multi.getFilesystemName("attachFile");
if (attachFile == null) {
attachFile = "";
} else {
byte[] byteStr = attachFile.getBytes();
int len = byteStr.length;
if (len > 50) {
File f = new File(savepath + "/" + attachFile);
if (f.isFile()) {
f.delete();
}
}
}
} catch (IOException ie) {
log.debug("첨부파일 용량 초과!!! 예외발생!!!");
throw ie;
}
2.File DownLoad
if(vo.getString("fileDown").equals("true")) {
request.setCharacterEncoding("EUC-KR");
String fileName = new String(request.getParameter("fileUrl").getBytes("ISO-8859-1"), "KSC5601");
String fileUrl = "WebContent/StyleUpload/" + fileName;
if(fileUrl == null) return;
boolean fileexists = true;
try {
ServletContext cxt = getServletConfig().getServletContext();
String file = cxt.getRealPath(fileUrl);
File fileEx = new File(file);
if(fileEx.exists()) {
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition","attachment; filename="+ java.net.URLEncoder.encode(fileName,"UTF-8"));
byte [] buffer = new byte[1024*15];
ServletOutputStream out = response.getOutputStream();
BufferedInputStream in = new BufferedInputStream(new FileInputStream(file));
BufferedOutputStream bout = new BufferedOutputStream(out);
int n = 0;
while((n=in.read(buffer, 0, 1024*15)) != -1) {
bout.write(buffer, 0, n);
bout.flush();
}
bout.close();
in.close();
} else {
fileexists = false;
}
} catch(Exception e) {
e.printStackTrace();
}
if(!fileexists) {
vo.put("message", MessageUtil.getMessage("MSG00009"));
}
}
3.File Delete
request.setCharacterEncoding("EUC-KR");String fileName = new String(request.getParameter("fileUrl").getBytes("ISO-8859-1"), "KSC5601");
String fileUrl = "WebContent/StyleUpload/" + fileName;
if(fileUrl == null) return;
boolean fileexists = true;
try
{
ServletContext cxt = getServletConfig().getServletContext();
String file = cxt.getRealPath(fileUrl);
File fileEx = new File(file);
if(fileEx.exists())
{
fileEx.delete();
}
}
catch(Exception e)
{
e.printStackTrace();
}