この記事の例は、参照のためにJavaのzipダウンロードを動的にエクスポートするための特定のコードを共有しています。特定のコンテンツは次のとおりです
パッケージpack.java.io.demo; Import java.io.bufferedoutputStream; Import java.io.file; Import java.io.fileinputStream; Import java.io.io.io.ioexception; Import java.text.simpledateFormat; Import Java.util.util.util.util.util.util.text. java.util.zip.zipentry; Import java.util.zip.zipoutputstream; Import jxl.workbook; Import jxl.format.alignment; Import jxl.format.border; Import.format.borderlinestyle; Import jxl.format.colour; Import.format.format.format.format.format.format.format.format.format.format.format.format.formmat.formmat.formmat.formmat. jxl.write.label; import jxl.write.writablecellformat; import jxl.write.writablefont; import jxl.write.writablesheet; import jxl.write.writableworkbook; import jxl.write.writeexception; import jxl.write.biff.rowsexexedededexception; /** * zip圧縮ファイルインスタンス * Zhou haitao * @author Administrator * */public class zipdemo {/** * @param args * @throws ioexception * @throws writeexception * @throws rowsex cehededexception */public static void main(string [] shrows writeexcepts、writeexexexexceptic 「c:/document/excel」; //フォルダーを作成します。 createfile(path); // Excelファイルを作成します。 createexcelfile(path); // .zipファイルを作成します。 Craetezippath(PATH); //ディレクトリ内のすべてのファイルを削除します。 file file = new file(path); //ファイルを削除します。 deleteexcelpath(file); //ファイルを再作成します。 file.mkdirs(); } /***フォルダーを作成します。 * @param path * @return */ public static string createfile(string path){file file = new file(path); //ファイルが存在するかどうかを判断します。 if(!file.exists()){// fileを作成します。 boolean bol = file.mkdirs(); if(bol){system.out.println(path+"パスが正常に作成された!"); } else {system.out.println(path+"path reacted faile!"); }} else {system.out.println(path+"ファイル既に存在する!"); }戻るパス; } /***指定されたディレクトリにExcelファイルを作成します。 * @param Path * @Throws IOException * @Throws WriteException * @Throws RowSex CehceedException */public static void createexcelfile(string path)throws ioexception、rowsexededexception、writeexception {for(int i = 0; i <3; i ++){// excel; writableworkbook workbook = workbook.createworkbook(new file(path+"/"+new SimpledateFormat( "yyyymmddhhmmsss")。 //最初のシートファイルを作成します。 WritableSheetシート= workbook.createsheet( "Export excel file"、0); //デフォルトの幅を設定します。 sheet.getSettings()。setDefaultColumnWidth(30); //フォントを設定します。 writablefont font1 = new writablefont(writablefont.arial、14、writablefont.bold、false、underlinestyle.no_underline、colour.red); writablecellformat cellformat1 = new writablecellformat(font1); //背景色を設定します。 cellformat1.setbackground(colour.blue_grey); //ボーダーを設定します。 cellformat1.setborder(border.all、borderlinestyle.dash_dot); //自動ラインラップを設定します。 cellformat1.setwrap(true); //テキストセンタリングアライメントを設定します。 cellformat1.setalignment(alignment.centre); //垂直センタリングを設定します。 cellformat1.setverticalAlignment(verticalAlignment.centre); //セルラベルラベル1 =新しいラベル(0、0、 "最初の行の最初のセル(自動的にラップするかどうかをテスト!)、Cellformat1);ラベルラベル2 =新しいラベル(1、0、「最初の行の2番目のセル」、Cellformat1);ラベルラベル3 =新しいラベル(2、0、最初の行の3番目のセル」、Cellformat1、First Label4 = labe4 = labe4 Cellformat1) writablefont.arial、14、writablefont、false、underlinesyline.no_underline.blue2); Cellformat2.All.all.thin) 「2番目のラベル」= 1列目のセル、cellformat2)。 workbook.close();日付()+" 0」 > 0){buf、0、len)ディレクトリ; if(bol){system.out.println( "delete succed!");上記はこの記事のすべての内容です。みんなの学習に役立つことを願っています。誰もがwulin.comをもっとサポートすることを願っています。