ダウンロードページ ( apache-ant-1.7.1-bin.zip ) ドキュメントページ ant.jar を追加 拡張子:txtvbswsfjsphpjavahtmlutf8sjis try { ZipFile zf = new ZipFile("C:\\apache-ant-1.7.1-bin.zip","shift_jis"); Iterator myIterator = (Iterator)zf.getEntries(); while( myIterator.hasNext() ) { ZipEntry ze = (ZipEntry)myIterator.next(); System.out.println(ze.getName()+"/"+ze.getCompressedSize()); if( !ze.isDirectory() ) { // 入力ZIP内エントリ InputStream inZipEntry = zf.getInputStream(ze); // 出力用 File realFile = new File( new File("C:\\user\\tmp"), ze.getName()); realFile.getParentFile().mkdirs(); FileOutputStream out = new FileOutputStream(realFile); // 出力 byte[] buf = new byte[4096]; int size = 0; while( (size = inZipEntry.read(buf)) != -1 ) { out.write(buf, 0, size); } out.close(); inZipEntry.close(); } } zf.close(); } catch ( Exception ex ) { ex.printStackTrace(); } 拡張子:txtvbswsfjsphpjavahtmlutf8sjis import javax.swing.SwingUtilities; import java.awt.BorderLayout; import javax.swing.JPanel; import javax.swing.JFrame; import jp.co.flatsoft.fscomponent.FSCalenderCombo; import java.awt.Rectangle; import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; import java.util.*; import org.apache.tools.zip.ZipEntry; import org.apache.tools.zip.ZipFile; import org.apache.tools.zip.ZipOutputStream; import javax.swing.JButton; public class Main extends JFrame { private static final long serialVersionUID = 1L; private JPanel jContentPane = null; private JButton jButton = null; /** * This method initializes jButton * * @return javax.swing.JButton */ private JButton getJButton() { if (jButton == null) { jButton = new JButton(); jButton.setBounds(new Rectangle(51, 54, 190, 28)); jButton.setText("実行"); jButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { try { ZipFile zf = new ZipFile("C:\\apache-ant-1.7.1-bin.zip","shift_jis"); Iterator myIterator = (Iterator)zf.getEntries(); while( myIterator.hasNext() ) { ZipEntry ze = (ZipEntry)myIterator.next(); System.out.println(ze.getName()+"/"+ze.getCompressedSize()); if( !ze.isDirectory() ) { // 入力ZIP内エントリ InputStream inZipEntry = zf.getInputStream(ze); // 出力用 File realFile = new File( new File("C:\\user\\tmp"), ze.getName()); realFile.getParentFile().mkdirs(); FileOutputStream out = new FileOutputStream(realFile); // 出力 byte[] buf = new byte[4096]; int size = 0; while( (size = inZipEntry.read(buf)) != -1 ) { out.write(buf, 0, size); } out.close(); inZipEntry.close(); } } zf.close(); } catch ( Exception ex ) { ex.printStackTrace(); } } }); } return jButton; } /** * @param args */ public static void main(String[] args) { // TODO 自動生成されたメソッド・スタブ SwingUtilities.invokeLater(new Runnable() { public void run() { Main thisClass = new Main(); thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); thisClass.setVisible(true); } }); } /** * This is the default constructor */ public Main() { super(); initialize(); } /** * This method initializes this * * @return void */ private void initialize() { this.setSize(300, 200); this.setContentPane(getJContentPane()); this.setTitle("JFrame"); } /** * This method initializes jContentPane * * @return javax.swing.JPanel */ private JPanel getJContentPane() { if (jContentPane == null) { jContentPane = new JPanel(); jContentPane.setLayout(null); jContentPane.add(getJButton(), null); } return jContentPane; } }
try { ZipFile zf = new ZipFile("C:\\apache-ant-1.7.1-bin.zip","shift_jis"); Iterator myIterator = (Iterator)zf.getEntries(); while( myIterator.hasNext() ) { ZipEntry ze = (ZipEntry)myIterator.next(); System.out.println(ze.getName()+"/"+ze.getCompressedSize()); if( !ze.isDirectory() ) { // 入力ZIP内エントリ InputStream inZipEntry = zf.getInputStream(ze); // 出力用 File realFile = new File( new File("C:\\user\\tmp"), ze.getName()); realFile.getParentFile().mkdirs(); FileOutputStream out = new FileOutputStream(realFile); // 出力 byte[] buf = new byte[4096]; int size = 0; while( (size = inZipEntry.read(buf)) != -1 ) { out.write(buf, 0, size); } out.close(); inZipEntry.close(); } } zf.close(); } catch ( Exception ex ) { ex.printStackTrace(); }
import javax.swing.SwingUtilities; import java.awt.BorderLayout; import javax.swing.JPanel; import javax.swing.JFrame; import jp.co.flatsoft.fscomponent.FSCalenderCombo; import java.awt.Rectangle; import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; import java.util.*; import org.apache.tools.zip.ZipEntry; import org.apache.tools.zip.ZipFile; import org.apache.tools.zip.ZipOutputStream; import javax.swing.JButton; public class Main extends JFrame { private static final long serialVersionUID = 1L; private JPanel jContentPane = null; private JButton jButton = null; /** * This method initializes jButton * * @return javax.swing.JButton */ private JButton getJButton() { if (jButton == null) { jButton = new JButton(); jButton.setBounds(new Rectangle(51, 54, 190, 28)); jButton.setText("実行"); jButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { try { ZipFile zf = new ZipFile("C:\\apache-ant-1.7.1-bin.zip","shift_jis"); Iterator myIterator = (Iterator)zf.getEntries(); while( myIterator.hasNext() ) { ZipEntry ze = (ZipEntry)myIterator.next(); System.out.println(ze.getName()+"/"+ze.getCompressedSize()); if( !ze.isDirectory() ) { // 入力ZIP内エントリ InputStream inZipEntry = zf.getInputStream(ze); // 出力用 File realFile = new File( new File("C:\\user\\tmp"), ze.getName()); realFile.getParentFile().mkdirs(); FileOutputStream out = new FileOutputStream(realFile); // 出力 byte[] buf = new byte[4096]; int size = 0; while( (size = inZipEntry.read(buf)) != -1 ) { out.write(buf, 0, size); } out.close(); inZipEntry.close(); } } zf.close(); } catch ( Exception ex ) { ex.printStackTrace(); } } }); } return jButton; } /** * @param args */ public static void main(String[] args) { // TODO 自動生成されたメソッド・スタブ SwingUtilities.invokeLater(new Runnable() { public void run() { Main thisClass = new Main(); thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); thisClass.setVisible(true); } }); } /** * This is the default constructor */ public Main() { super(); initialize(); } /** * This method initializes this * * @return void */ private void initialize() { this.setSize(300, 200); this.setContentPane(getJContentPane()); this.setTitle("JFrame"); } /** * This method initializes jContentPane * * @return javax.swing.JPanel */ private JPanel getJContentPane() { if (jContentPane == null) { jContentPane = new JPanel(); jContentPane.setLayout(null); jContentPane.add(getJButton(), null); } return jContentPane; } }