아는 것이 좋은 것이다.

[Java] 파일 업로드, 임시파일 생성 본문

Java Programing

[Java] 파일 업로드, 임시파일 생성

start0 2015. 1. 21. 11:24

public void writeFile(MultipartHttpServletRequest file, HttpServletRequest request) throws IOException {

File path = new File(request.getRealPath("/resources/upload/"));

String fileName = file.getFile("filename").getOriginalFilename();

File destination = File.createTempFile("file", fileName, path);


FileCopyUtils.copy(file.getFile("filename").getInputStream(), new FileOutputStream(destination));

System.out.println("filePath: " + destination.getAbsolutePath());

System.out.println("fileName: " + file.getFile("filename").getOriginalFilename());

System.out.println("fileSize: " + file.getFile("filename").getSize());

System.out.println(path.hashCode());

//destination.deleteOnExit(); // 생성된 임시파일 삭제

}

Comments