import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.Enumeration; import javax.swing.JOptionPane; import jp.hishidama.zip.ZipEntry; import jp.hishidama.zip.ZipOutputStream; import jp.hishidama.zip.ZipFile; import jp.hishidama.zip.ZipPasswordException; //***************************************************************** //*** このクラスにimportされているZIPは、jp.hishidama.zipである *** //***************************************************************** public class ArchivePasswordTestPassZip { // ArchivePasswordTest panel; File folder; //------------------------------------------------------------------コンストラクタ // public ArchivePasswordTestPassZip(ArchivePasswordTest parent){ panel=parent; } //------------------------------------------------------------------ZIP情報取得 // public String outputZipInfo(File file){ StringBuffer buf=new StringBuffer(); // try{ buf.append(outputZipFileEntries(new ZipFile(file))+"\n"); }catch(IOException e){ return e.toString(); } // return buf.toString(); } //格納ファイルの個々の情報 private String outputZipFileEntries(ZipFile zipFile){ StringBuffer buf=new StringBuffer(); // Enumeration enm=zipFile.entries(); buf.append("*** ZIP File Entries (by jp.hishidama.zip) ***"+"\n"); // while(enm.hasMoreElements()){ buf.append(((ZipEntry)enm.nextElement()).getName()+"\n"); } // return buf.toString(); } //------------------------------------------------------------------ZIP圧縮(パスワード付きに対応) // public void filesToPasswordZip(File fileZip,File baseFolder,String password){ // folder=baseFolder; // try{ ZipOutputStream zos=new ZipOutputStream(new FileOutputStream(fileZip)); if(!password.equals("")){ //パスワードがあれば設定 zos.setPassword(password.getBytes("MS932")); } // filesToZip(folder,zos); // zos.close(); // JOptionPane.showMessageDialog(panel,"圧縮しました(by jp.hishidama.zip)","完了",JOptionPane.INFORMATION_MESSAGE); } catch (IOException ioe) { JOptionPane.showMessageDialog(panel,ioe.toString(),"エラー",JOptionPane.ERROR_MESSAGE); } } //指定されたフォルダ以下にある全ファイルをZIPに書き込む(再帰呼び出し) private void filesToZip(File outFolder,ZipOutputStream zos) throws IOException{ String[] outFilesList=outFolder.list(); // File outFile; for(int f=0;f