ソース掲示板




すべてから検索

キーワード   条件 表示 現行ログ 過去ログ トピックス 名前 本文
Java : Eclipse + VisualEditor + LZH参照と解凍
日時: 2009/10/02 10:41
名前: lightbox



ダウンロードページ
拡張子:
jar では無く、ソースコードなので Eclipse の src を右クリックしてインポートします
( ファイルシステムで、解凍した jlhasrc_20050504.tar ディレクトリを参照して、jp のみをチェックします )
jlhasrc_20050504.tar
	jp
		gr
			java_conf
				dangan
					io
					lang
					util

インポートされた名前空間のトップでプロパティを表示して、キャラクタセットを MS932 に変更します
( デフォルトで MS932 になっている場合は必要ありません )
ドキュメントは、ダウンロードページの jlhadoc_20050504.tar.gz です。 jar にしたい場合は、jp... 関連を全て選択した状態でエクスポートし、Java の JAR ファイルを選択 して出力します。
拡張子:
try {
	LhaFile lhaFile = new LhaFile("C:\\laylaClass\\WinOfSql102.lzh");
	Enumeration<?> myEnum = lhaFile.entries();
	while( myEnum.hasMoreElements() ) {
		LhaHeader lhaHeader = (LhaHeader)myEnum.nextElement();
		System.out.println(lhaHeader.getPath()+"/"+lhaHeader.getCompressedSize());
		
		InputStream inZipEntry = lhaFile.getInputStream(lhaHeader);
		// 出力用
		File realFile = new File( new File("C:\\user\\tmp"), lhaHeader.getPath());
		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();
		
	}
	lhaFile.close();
	
}
catch( Exception ex ) {
	ex.printStackTrace();
}
拡張子:
import javax.swing.SwingUtilities;
import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.Rectangle;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.Enumeration;

import jp.gr.java_conf.dangan.util.lha.LhaFile;
import jp.gr.java_conf.dangan.util.lha.LhaHeader;


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(58, 43, 170, 37));
			jButton.setText("実行");
			jButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
					try {
						LhaFile lhaFile = new LhaFile("C:\\laylaClass\\WinOfSql102.lzh");
						Enumeration<?> myEnum = lhaFile.entries();
						while( myEnum.hasMoreElements() ) {
							LhaHeader lhaHeader = (LhaHeader)myEnum.nextElement();
							System.out.println(lhaHeader.getPath()+"/"+lhaHeader.getCompressedSize());
							
							InputStream inZipEntry = lhaFile.getInputStream(lhaHeader);
							// 出力用
							File realFile = new File( new File("C:\\user\\tmp"), lhaHeader.getPath());
							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();
							
						}
						lhaFile.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;
	}

}
メンテナンス


日時: 2009/10/02 10:41
名前: lightbox