導航:首頁 > 編程語言 > java創建包

java創建包

發布時間:2023-10-02 09:00:52

Ⅰ 如何在java里包中建包

第一步:在需要創建包的路徑上右擊,選擇」new「,之後選擇」package「;

Ⅱ 如何用java創建一個加密壓縮

下面的示例代碼演示如何創建zip壓縮包。
首先需要由需要壓縮的文件創建一個InputStream對象,然後讀取文件內容寫入到ZipOutputStream中。
ZipOutputStream類接受FileOutputStream作為參數。創建號ZipOutputStream對象後需要創建一個zip entry,然後寫入。

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

/**
*
* @author outofmemory.cn
*/
public class Main {

/**
* Creates a zip file
*/

public void createZipFile() {

try {
String inputFileName = "test.txt";
String zipFileName = "compressed.zip";

//Create input and output streams
FileInputStream inStream = new FileInputStream(inputFileName);
ZipOutputStream outStream = new ZipOutputStream(new FileOutputStream(zipFileName));

// Add a zip entry to the output stream
outStream.putNextEntry(new ZipEntry(inputFileName));

byte[] buffer = new byte[1024];
int bytesRead;

//Each chunk of data read from the input stream
//is written to the output stream
while ((bytesRead = inStream.read(buffer)) > 0) {
outStream.write(buffer, 0, bytesRead);
}

//Close zip entry and file streams
outStream.closeEntry();

outStream.close();
inStream.close();

} catch (IOException ex) {
ex.printStackTrace();
}
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
new Main().createZipFile();
}

閱讀全文

與java創建包相關的資料

熱點內容
MFC經典游戲編程 瀏覽:781
在線申請小額貸款源碼 瀏覽:328
多個文件夾如何批量刪除內容 瀏覽:246
電力載波單片機 瀏覽:591
單片機串列通訊 瀏覽:515
遍歷兩個對應列表python 瀏覽:491
數控編程演示軟體哪裡下載 瀏覽:686
程序員會6點下班嗎 瀏覽:791
linuxdate時區 瀏覽:325
小說伺服器怎麼選 瀏覽:526
python自動化測試框架哪個最好 瀏覽:311
反編譯後為什麼不能回編 瀏覽:54
java反射獲得屬性值 瀏覽:39
程序員和甲方的矛盾 瀏覽:128
在地獄做程序員 瀏覽:765
銀行app能做什麼 瀏覽:238
追書緩存的小說在哪個文件夾 瀏覽:563
山科女生程序員 瀏覽:748
mybatis3源碼分析 瀏覽:467
華為交換機常用配置命令 瀏覽:378