어느 카탈리나에 저장납니다
String rootPath = System.getProperty("catalina.home");
File dir = new File(rootPath + File.separator + "yourfolderName");
if (!dir.exists())
dir.mkdirs();
// Create the file on server
java.util.Date date= new java.util.Date();
String Path = dir.getAbsolutePath() + File.separator + (new Timestamp(date.getTime())).toString().replace(":", "").toString().replace(".", ".").toString().replace(" ","").toString().replace("-","").toString()+".pdf";
또는 프로젝트에 폴더를 만들고 거기에 저장하십시오.
if (!file.isEmpty()) {
//filter for checking file extewnsion
if(file.getContentType().equalsIgnoreCase("image/jpg") || file.getContentType().equalsIgnoreCase("image/jpeg")){
//if file is >2 MB or < 2MB
double size = file.getSize();
double kilobytes = (size/1024);
double megabytes = (kilobytes/1024);
if(megabytes<2){
try {
byte[] bytes = file.getBytes();
String filePath = request.getRealPath("/")+"yourFolderName\\ProfileImages\\"+SessionManagement.getUserName()+".jpg";
BufferedOutputStream stream =
new BufferedOutputStream(new FileOutputStream(new File(filePath)));
stream.write(bytes);
stream.close();
//console call
}
else{
model.put("error", "Please select File less than 2 MB");
return new ModelAndView("uploadPhotoTile");
}
}else{
model.put("error", "Please select JPEG File");
return new ModelAndView("uploadPhotoTile");
}
} else {
model.put("error", "Please select File");
return new ModelAndView("uploadPhotoTile");
}
파일을 다운로드 하시겠습니까? –
아니요, WebContent의 특정 폴더에 업로드하려고합니다. –
구체적인 문제를 명확히하거나 추가 정보를 추가하여 필요한 것을 정확하게 강조하십시오. 현재 작성된 내용이므로 귀하가 원하는 내용을 정확하게 말하기는 어렵습니다. How to Ask 페이지에서이 질문에 대한 설명을 참조하십시오. –