본문 바로가기

study/java

파일복사하기

public String main(HttpServletRequest req,Model model,Authentication authentication
,Gson gson,InfoVo infoVo
) throws Exception{


String UploadPath1,UploadPath2;


String[] mapperArr = {"noti", "banner"};
String[] serviceArr = {"notiData", "bannerData"};
infoVo.setcode("list"); 
infoVo.setindexPage(0);
infoVo.setpageSize(10000);
String str = "banner"; 
List<InfoVo> Lst = infoService.bannerData(infoVo);  
UploadPath1 = gp.getProperty("upload.server.uploadPath")+"/";
UploadPath2 = gp.getProperty("upload.server.uploadPath")+"/"+str+"/";
File Folder2 =new File(UploadPath2); // 생성돈 신규 폴더
File Folder1 =new File(UploadPath1);  // 기존 업로드 폴더

if (!Folder2.exists()) {
try{
Folder2.mkdir(); //폴더 생성합니다.
    System.out.println("폴더가 생성되었습니다.");       
    log.debug(Lst.size());
        } 
        catch(Exception e){
    e.getStackTrace();
}        
         }else {
System.out.println("이미 폴더가 생성되어 있습니다.");
}

log.debug(Lst.size());
     for(int i=0;i<Lst.size();i++) {
     File cpFile = new File(Folder1+"/"+Lst.get(i).getATCH1().toString());
     File cpdFile = new File(Folder2+"/"+Lst.get(i).getATCH1().toString()); 
        FileInputStream input = new FileInputStream(cpFile);
        FileOutputStream output = new FileOutputStream(cpdFile);
        byte[] buf = new byte[4096];
        int readData;
        while ((readData = input.read(buf)) > 0) {
            output.write(buf, 0, readData);
        }
        input.close();
        output.close();    
     }
     

     
return "/config/main";
}