導航:首頁 > 文件處理 > java壓縮版

java壓縮版

發布時間:2022-05-08 12:03:56

『壹』 java8 64位壓縮

官網下載地址:http://www.oracle.com/technetwork/java/javase/downloads/index.html

建議去官網下載,不要用別人的包

『貳』 java壓縮解壓縮.對於壓縮包下,如果只是文件的話解壓縮沒有問題,如果壓縮包下有文件夾就會出錯.

給你一個例子看一下。
-----------------------------------------------
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream;

public class Test {

public static void main(String[] args) throws Exception {
File file = new File("D:\\docs\\chm\\zip\\01.zip");
File outFile = new File("D:\\docs\\chm\\zip");
ZipFile zipFile = new ZipFile(file);
ZipInputStream zipInput = new ZipInputStream(new FileInputStream(file));
ZipEntry entry = null;
InputStream input = null;
OutputStream out = null;
int len = 0;
byte[] buff = new byte[4096];
while ((entry = zipInput.getNextEntry()) != null) {
String name = entry.getName();
File dest = new File(outFile, name);
if (entry.isDirectory()) {
dest.mkdirs();
} else {
dest.getParentFile().mkdirs();
input = zipFile.getInputStream(entry);
out = new FileOutputStream(dest);
while ((len = input.read(buff)) != -1) {
out.write(buff, 0, len);
}
out.close();
input.close();
}
}
}

}

『叄』 Java裡面怎麼導入壓縮包

首先解壓。 File->New->Java Project 不用填project,不要選擇use default location, 然後browse是選擇要導入的java項目; 如果只是java源文件的話,你就用Eclipse新建一個項目,然後把文件粘到項目的src文件夾下即可。

『肆』 在網上下載下來的JAVA軟體壓縮包怎麼安裝到手機里

只要在電腦上找到游戲然後下載不過型號要對應,然後你啟動JAVA那裡有一個安裝新程序,你點一下看你下載的東西在手機上還是內存卡上,然後選擇就可以了!我的手機就是這樣,不知道你的可以不可以…不過我勸你還是不要下載很多游戲玩的時候都要錢!

『伍』 java中如何保證下載的壓縮包命名中有中文

在使用Java對ZIP壓縮文件進行解壓的方式中有兩種,一種是使用apache提供的ant.jar工具包,但是如果ZIP文件中含有中文名稱的文件,在解壓後,文件名將出現亂碼,另一種是使用Java自身JDK中java.util.zip包下工具類,但是同樣如果有中文名的情況下依然會出現亂碼情況。因此對於這種亂碼的處理,一種是修改JDK下的幾個源文件,一種就是把需要用的JDK源文件重新反編譯進行處理,單獨放在一個包中,在使用的時候,調用自己處理過的包中文件進行處理即可。附件tools.rar壓縮文件是我進行處理過後的需要調用到的java源程序,主要為Deflater.java,DeflaterOutputStream.java,InflaterInputStream.java,ZipConstants.java,ZipEntry.java,ZipInputStram.java,ZipOutputStream.java文件,同時包含一個解壓縮文件CompressZipFile.java

『陸』 如何使用java壓縮文件夾成為zip包(最簡單的

import java.io.File;

public class ZipCompressorByAnt {

private File zipFile;

/**
* 壓縮文件構造函數
* @param pathName 最終壓縮生成的壓縮文件:目錄+壓縮文件名.zip
*/
public ZipCompressorByAnt(String finalFile) {
zipFile = new File(finalFile);
}

/**
* 執行壓縮操作
* @param srcPathName 需要被壓縮的文件/文件夾
*/
public void compressExe(String srcPathName) {
System.out.println("srcPathName="+srcPathName);

File srcdir = new File(srcPathName);
if (!srcdir.exists()){
throw new RuntimeException(srcPathName + "不存在!");
}

Project prj = new Project();
Zip zip = new Zip();
zip.setProject(prj);
zip.setDestFile(zipFile);
FileSet fileSet = new FileSet();
fileSet.setProject(prj);
fileSet.setDir(srcdir);
//fileSet.setIncludes("**/*.java"); //包括哪些文件或文件夾 eg:zip.setIncludes("*.java");
//fileSet.setExcludes(...); //排除哪些文件或文件夾
zip.addFileset(fileSet);
zip.execute();
}

}

public class TestZip {

public static void main(String[] args) {

ZipCompressorByAnt zca = new ZipCompressorByAnt("E:\test1.zip ");
zca.compressExe("E:\test1");
}

}

/*如果 出現ant 的 52 51 50 等版本問題 可以去找對應的ant-1.8.2.jar 我開始用的ant-1.10.1.jar 就是這個包版本高了 一直報verson 52 版本問題*/

『柒』 java壓縮包怎麼安裝到手機裡面

看下擴展名一般能識別的是
.WAR
.JAD
.JAR
這三種
其中.WAR是網上下載的包。知識OTA下載安裝的可以直接運行
.JAD & JAR 是可以執行的。其中JAD只是描述文件,JAR才是最核心的內容
有的文件只有JAR文件,也可以直接點擊運行。如果有JAD文件的,先點JAD。不然可能會有些頭的信息丟失,比如虛擬鍵盤,指示器等沒法全屏。或者根本沒有網路或存儲許可權。

注意下你下載的文件是不是這3個擴展名。一般網路資源都通過第三方壓縮工具壓縮下,這樣空間小便於上傳和下載。一般壓縮後的文件是.ZIP或者.RAR文件。如果是這樣就需要你先解壓下。解壓後就應該能看到JAD和JAR了。然後在手機上在點JAR安裝或運行。

一般手機不具備解壓ZIP或RAR功能。這樣你用電腦先把RAR或者ZIP先解壓好。然後通過數據線把解壓後的文件傳到手機里。

還有一點。就是軟體適配性的問題。矛盾就是這個軟體版本和你的手機根本不兼容。這樣安裝了也玩不了。正規的安裝途徑應該是在你瀏覽WAP頁面時會有指示性的安裝提示。引導你找到適合自己記性的軟體包。

『捌』 怎樣用java快速實現zip文件的壓縮解壓縮

packagezip;
importjava.io.BufferedInputStream;
importjava.io.BufferedOutputStream;
importjava.io.File;
importjava.io.FileInputStream;
importjava.io.FileOutputStream;
importjava.util.Enumeration;
importjava.util.zip.CRC32;
importjava.util.zip.CheckedOutputStream;
importjava.util.zip.ZipEntry;
importjava.util.zip.ZipFile;
importjava.util.zip.ZipOutputStream;
importorg.apache.commons.lang3.StringUtils;
publicclassZipUtil{

/**
*遞歸壓縮文件夾
*@paramsrcRootDir壓縮文件夾根目錄的子路徑
*@paramfile當前遞歸壓縮的文件或目錄對象
*@paramzos壓縮文件存儲對象
*@throwsException
*/
privatestaticvoidzip(StringsrcRootDir,Filefile,ZipOutputStreamzos)throwsException
{
if(file==null)
{
return;
}

//如果是文件,則直接壓縮該文件
if(file.isFile())
{
intcount,bufferLen=1024;
bytedata[]=newbyte[bufferLen];

//獲取文件相對於壓縮文件夾根目錄的子路徑
StringsubPath=file.getAbsolutePath();
intindex=subPath.indexOf(srcRootDir);
if(index!=-1)
{
subPath=subPath.substring(srcRootDir.length()+File.separator.length());
}
ZipEntryentry=newZipEntry(subPath);
zos.putNextEntry(entry);
BufferedInputStreambis=newBufferedInputStream(newFileInputStream(file));
while((count=bis.read(data,0,bufferLen))!=-1)
{
zos.write(data,0,count);
}
bis.close();
zos.closeEntry();
}
//如果是目錄,則壓縮整個目錄
else
{
//壓縮目錄中的文件或子目錄
File[]childFileList=file.listFiles();
for(intn=0;n<childFileList.length;n++)
{
childFileList[n].getAbsolutePath().indexOf(file.getAbsolutePath());
zip(srcRootDir,childFileList[n],zos);
}
}
}

/**
*對文件或文件目錄進行壓縮
*@paramsrcPath要壓縮的源文件路徑。如果壓縮一個文件,則為該文件的全路徑;如果壓縮一個目錄,則為該目錄的頂層目錄路徑
*@paramzipPath壓縮文件保存的路徑。注意:zipPath不能是srcPath路徑下的子文件夾
*@paramzipFileName壓縮文件名
*@throwsException
*/
publicstaticvoidzip(StringsrcPath,StringzipPath,StringzipFileName)throwsException
{
if(StringUtils.isEmpty(srcPath)||StringUtils.isEmpty(zipPath)||StringUtils.isEmpty(zipFileName))
{
thrownewParameterException(ICommonResultCode.PARAMETER_IS_NULL);
}
CheckedOutputStreamcos=null;
ZipOutputStreamzos=null;
try
{
FilesrcFile=newFile(srcPath);

//判斷壓縮文件保存的路徑是否為源文件路徑的子文件夾,如果是,則拋出異常(防止無限遞歸壓縮的發生)
if(srcFile.isDirectory()&&zipPath.indexOf(srcPath)!=-1)
{
thrownewParameterException(ICommonResultCode.INVALID_PARAMETER,".");
}

//判斷壓縮文件保存的路徑是否存在,如果不存在,則創建目錄
FilezipDir=newFile(zipPath);
if(!zipDir.exists()||!zipDir.isDirectory())
{
zipDir.mkdirs();
}

//創建壓縮文件保存的文件對象
StringzipFilePath=zipPath+File.separator+zipFileName;
FilezipFile=newFile(zipFilePath);
if(zipFile.exists())
{
//檢測文件是否允許刪除,如果不允許刪除,將會拋出SecurityException
=newSecurityManager();
securityManager.checkDelete(zipFilePath);
//刪除已存在的目標文件
zipFile.delete();
}

cos=newCheckedOutputStream(newFileOutputStream(zipFile),newCRC32());
zos=newZipOutputStream(cos);

//如果只是壓縮一個文件,則需要截取該文件的父目錄
StringsrcRootDir=srcPath;
if(srcFile.isFile())
{
intindex=srcPath.lastIndexOf(File.separator);
if(index!=-1)
{
srcRootDir=srcPath.substring(0,index);
}
}
//調用遞歸壓縮方法進行目錄或文件壓縮
zip(srcRootDir,srcFile,zos);
zos.flush();
}
catch(Exceptione)
{
throwe;
}
finally
{
try
{
if(zos!=null)
{
zos.close();
}
}
catch(Exceptione)
{
e.printStackTrace();
}
}
}

/**
*解壓縮zip包
*@paramzipFilePathzip文件的全路徑
*@paramunzipFilePath解壓後的文件保存的路徑
*@paramincludeZipFileName解壓後的文件保存的路徑是否包含壓縮文件的文件名。true-包含;false-不包含
*/
@SuppressWarnings("unchecked")
publicstaticvoinzip(StringzipFilePath,StringunzipFilePath,booleanincludeZipFileName)throwsException
{
if(StringUtils.isEmpty(zipFilePath)||StringUtils.isEmpty(unzipFilePath))
{
thrownewParameterException(ICommonResultCode.PARAMETER_IS_NULL);
}
FilezipFile=newFile(zipFilePath);
//如果解壓後的文件保存路徑包含壓縮文件的文件名,則追加該文件名到解壓路徑
if(includeZipFileName)
{
StringfileName=zipFile.getName();
if(StringUtils.isNotEmpty(fileName))
{
fileName=fileName.substring(0,fileName.lastIndexOf("."));
}
unzipFilePath=unzipFilePath+File.separator+fileName;
}
//創建解壓縮文件保存的路徑
FileunzipFileDir=newFile(unzipFilePath);
if(!unzipFileDir.exists()||!unzipFileDir.isDirectory())
{
unzipFileDir.mkdirs();
}

//開始解壓
ZipEntryentry=null;
StringentryFilePath=null,entryDirPath=null;
FileentryFile=null,entryDir=null;
intindex=0,count=0,bufferSize=1024;
byte[]buffer=newbyte[bufferSize];
BufferedInputStreambis=null;
BufferedOutputStreambos=null;
ZipFilezip=newZipFile(zipFile);
Enumeration<ZipEntry>entries=(Enumeration<ZipEntry>)zip.entries();
//循環對壓縮包里的每一個文件進行解壓
while(entries.hasMoreElements())
{
entry=entries.nextElement();
//構建壓縮包中一個文件解壓後保存的文件全路徑
entryFilePath=unzipFilePath+File.separator+entry.getName();
//構建解壓後保存的文件夾路徑
index=entryFilePath.lastIndexOf(File.separator);
if(index!=-1)
{
entryDirPath=entryFilePath.substring(0,index);
}
else
{
entryDirPath="";
}
entryDir=newFile(entryDirPath);
//如果文件夾路徑不存在,則創建文件夾
if(!entryDir.exists()||!entryDir.isDirectory())
{
entryDir.mkdirs();
}

//創建解壓文件
entryFile=newFile(entryFilePath);
if(entryFile.exists())
{
//檢測文件是否允許刪除,如果不允許刪除,將會拋出SecurityException
=newSecurityManager();
securityManager.checkDelete(entryFilePath);
//刪除已存在的目標文件
entryFile.delete();
}

//寫入文件
bos=newBufferedOutputStream(newFileOutputStream(entryFile));
bis=newBufferedInputStream(zip.getInputStream(entry));
while((count=bis.read(buffer,0,bufferSize))!=-1)
{
bos.write(buffer,0,count);
}
bos.flush();
bos.close();
}
}

publicstaticvoidmain(String[]args)
{
StringzipPath="d:\ziptest\zipPath";
Stringdir="d:\ziptest\rawfiles";
StringzipFileName="test.zip";
try
{
zip(dir,zipPath,zipFileName);
}
catch(Exceptione)
{
e.printStackTrace();
}

StringzipFilePath="D:\ziptest\zipPath\test.zip";
StringunzipFilePath="D:\ziptest\zipPath";
try
{
unzip(zipFilePath,unzipFilePath,true);
}
catch(Exceptione)
{
e.printStackTrace();
}
}
}

『玖』 如何用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壓縮版相關的資料

熱點內容
安卓手機怎麼用愛思助手傳文件進蘋果手機上 瀏覽:833
安卓怎麼下載60秒生存 瀏覽:793
外向式文件夾 瀏覽:225
dospdf 瀏覽:420
怎麼修改騰訊雲伺服器ip 瀏覽:377
pdftoeps 瀏覽:483
為什麼鴻蒙那麼像安卓 瀏覽:726
安卓手機怎麼拍自媒體視頻 瀏覽:176
單片機各個中斷的初始化 瀏覽:714
python怎麼集合元素 瀏覽:470
python逐條解讀 瀏覽:822
基於單片機的濕度控制 瀏覽:488
ios如何使用安卓的帳號 瀏覽:874
程序員公園采訪 瀏覽:802
程序員實戰教程要多長時間 瀏覽:965
企業數據加密技巧 瀏覽:125
租雲伺服器開發 瀏覽:804
程序員告白媽媽不同意 瀏覽:327
攻城掠地怎麼查看伺服器 瀏覽:592
android開機黑屏 瀏覽:568