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

熱點內容
單片機頻率變化 瀏覽:428
哪個app可以看賭神 瀏覽:466
rstudiopython 瀏覽:127
團隊如何開發伺服器 瀏覽:440
php選擇資料庫的函數 瀏覽:772
dhcp伺服器新增地址 瀏覽:930
程序員跑三個月外賣 瀏覽:941
linux配置tomcat的jdk路徑 瀏覽:363
液體壓縮公式 瀏覽:777
php開發後台管理系統 瀏覽:360
python二分查找遞歸 瀏覽:447
微信如何發視頻不壓縮 瀏覽:902
河北2021美術高考綜合分演算法 瀏覽:606
如何為電腦文件夾加密 瀏覽:835
電腦自啟動應用命令 瀏覽:690
php判斷一個文件是否存在 瀏覽:829
php導出xml文件 瀏覽:904
7個文件夾解壓 瀏覽:383
python實現機器碼 瀏覽:356
jpeg壓縮器 瀏覽:98