2
음 .2 .xml 파일을 생성하고 있지만 폴더에 저장하고 압축하여 생성하고 싶지 않습니다. 별도로 폴더에서 분리되어 압축됩니다. d 당신은 그것을 얻었습니까?코드에서 생성 된 파일을 압축하는 방법 (Java)
나는 두 파일을 폴더에 넣고 집어 넣기를 원합니다. 저장하려는 유일한 것은 zip 파일입니다. 그것은 당신의 문제에 대한 답처럼 보이는
String name = fields.find(chooser.getLocation(), "mimic");
Mimic mimic = getMimic(mimicList.get(0));
String fileName = chooser.getSelectedFile().toString() + File.separator + "des_" +nombreMimic.substring(0, nombreMimic.length()-4)+ ".xml";
String config = chooser.getSelectedFile().toString() + File.separator + "cfg_" +nombreMimic.substring(0, nombreMimic.length()-4)+".xml";
FileOutputStream file;
FileOutputStream file2;
file = new FileOutputStream(fileName);
file2 =new FileOutputStream(config);
Parser parser;
parser = new Parser(file,new String[]{});
parser.render(mimic , fields);
JOptionPane.showMessageDialog(null, "Complete!");
Parser2 parser2;
parser2 = new Parser2(file2,new String[]{});
parser2.render(mimic , fields);
JOptionPane.showMessageDialog(null, "Complete!");
FileInputStream inputStream = new FileInputStream(chooser.getSelectedFile().toString() + File.separator + "des_" +nombreMimic.substring(0, nombreMimic.length()-4)+ ".xml");
ZipOutputStream zip = new ZipOutputStream(new FileOutputStream(nombreMimic.substring(0, nombreMimic.length()-4)+".des"));
zip.putNextEntry(new ZipEntry(fileName));
byte [] buffer = new byte [1024];
int bytesRead;
while((bytesRead=inputStream.read(buffer))>0){
zip.write(buffer,0,bytesRead);
}
zip.closeEntry();
zip.close();
inputStream.close();
} catch (Exception ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
JOptionPane.showMessageDialog(null, "Error parsing");
}
}
}
}
Java 7을 사용하고 있습니까? – fge
아니 아주 이전. 업데이트가 옵션이 아닙니다. 다른 항목에 통합 될 것입니다. –