導航:首頁 > 編程語言 > 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創建包相關的資料

熱點內容
國外視屏播放軟體推薦與分析 瀏覽:81
什麼APP可以看韓國電影?推薦幾款熱門APP 瀏覽:142
泰星馬里奧電影:重新定義經典游戲角色 瀏覽:234
uc能用的網站 | UC瀏覽器必備:優質實用網站推薦 瀏覽:201
10w3,com,:10w3的意義和應用 瀏覽:74
小慧小雅彪哥電影名叫啥-探尋童年奇幻世界 瀏覽:978
阜陽兼職程序員多少錢 瀏覽:383
十部必看變種人電影:探索變種人世界的精彩故事 瀏覽:902
活著春生的結局:生命的意義與希望 瀏覽:38
西門慶吃葡萄盪鞦韆視頻的魅力與影響力 瀏覽:716
朱茵和郝劭文的電影作品:演技與魅力的結合 瀏覽:157
朴初炫的所有電影:朴初炫的電影作品及其影響力 瀏覽:587
於小光:引領時代潮流的商業智慧 瀏覽:574
惡棍老哥:毀滅與救贖的雙重邊緣 瀏覽:438
三級副利電影:歷史、吸引力與影響 瀏覽:638
有部電影裡面男主角叫虎子 瀏覽:94