티스토리 툴바


String path = "c:/";
String files = xxx+".TXT";

File txtFile = new File(path + "/ordering/" + files);

 

try{

        File f = new File("c:\\ordering");

        //디렉토리 유무 체크 생성.
        if(!f.exists()){         
             f.mkdir();
        }

        BufferedWriter out = new BufferedWriter(new FileWriter(txtFile));    //아웃풋스트림 생성
       
        //loop
        out.write("gogogo");
        out.flush();       

        out.newLine(); //줄 띄우기

        out.write("gogogo");
        out.flush();       

        out.close();
       
       // Create the ZIP file
        String outFilename = "c:/ordering/"+xxx+".zip";
        ZipOutputStream zOS = new ZipOutputStream(new FileOutputStream(outFilename));
          
       FileInputStream in = new FileInputStream( path + "/ordering/" + files);

       zOS.putNextEntry(new ZipEntry(files));
        
       byte[] buf = new byte[1024];

       int len;
       while ((len = in.read(buf)) > 0) {
                    zOS.write(buf, 0, len);
                }   
       zOS.closeEntry();
       
        in.close();
       zOS.close();
       
}catch(Exception ie){
       log.error(ie);

}finally{
//        파일 압축후 삭제.
           txtFile.delete();

}


출처:http://blog.naver.com/xxeno?Redirect=Log&logNo=150035788373

Posted by 새벽여행