導航:首頁 > 文件處理 > javazip壓縮的文件怎麼打開

javazip壓縮的文件怎麼打開

發布時間:2022-06-21 22:09:29

① 下載了一個java程序,是zip包格式的,請問應該怎麼運行

這是一個輕量級的Java神經網路的框架,首先你電腦上必須按照jre .
To use Neuroph in your Java appliacation add reference to neuroph-2.6.jar and all jars from lib folder from this distribution, and import required classes.
You can create and train neural networks using NeurophStudio GUI, and load them in you app, or you can create and train them directly from code using Neuroph API.
See getting started doc for more details.
把neuroph-2.6.jar 放到你的項目中,如web 項目的lib 文件夾下。就可以用了。這個不是引用程序,不能直接運行。要使用可以網路下 neuroph 去找下api

② 用JAVA ZipOutputStream做的文件壓縮 壓完後用PC上的解壓縮軟體能打開嗎

測試了一下,壓縮一jpg文件後用好壓可以正常打開

③ java代碼實現 導出zip包,無法打開zip壓縮包

package com.lch.test;

import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

public class ZIP {
public static void main(String[] argv) throws Exception {
ZipFile zf = new ZipFile("E:\\wk\\LBSLEMIS201106141057\\LBSLEMIS\\test\\com\\lch\\test\\filename.zip");

for (Enumeration entries = zf.entries(); entries.hasMoreElements();) {
String zipEntryName = ((ZipEntry) entries.nextElement()).getName();
System.out.println(zipEntryName);
}
}
}

用javad 的ZipFile類的ZipEntry方法試一下 找到ZIP裡面的ZipEntry方法 讀取Zip裡面壓縮文件的內容

有可能會引用外包

你好,我不知道你說的dzp是什麼格式文件,但如果是zip的壓縮文件,可以看下我的這段代碼

ZipFile file = new ZipFile("d:\\1.zip");
ZipEntry entry = file.getEntry("1.xml"); //假如壓縮包里的文件名是1.xml
InputStream in=file.getInputStream(entry);
最後就是按照java中一貫的流的處理方式即可

可以不解壓,zip包里的一個對象就是一個ZipEntry
找到你想要的那個ZipEntry,用文流寫出來就可以了。追問通過ZipEntry,然後用流就可以讀出裡面的內容了嗎?謝謝指點!
回答/**
* 解壓
* @param root 輸出目標
* @param zipfile zip文件
*/
protected void unzip(File root, File zipfile, String file) throws Exception {

// 解壓文件不存在時返回
if (!zipfile.exists()) {
return;
}
// 釋放目錄不存時創建
if (!root.exists()) {
root.mkdirs();
}
// 釋放目錄不為目錄時返回
if (!root.isDirectory()) {
return;
}

FileInputStream fin = new FileInputStream(zipfile);
ZipInputStream zin = new ZipInputStream(fin);
ZipEntry entry = null;

while ((entry = zin.getNextEntry()) != null) {
// if (!entry.getName().endsWith(file)) {
// continue;
// }
File tmp = new File(root, entry.getName());
if (entry.isDirectory()) {
tmp.mkdirs();
} else {
byte[] buff = new byte[4096];
int len = 0;
tmp.getParentFile().mkdirs();
FileOutputStream fout = new FileOutputStream(tmp);
while ((len = zin.read(buff)) != -1) {
fout.write(buff, 0, len);
}
zin.closeEntry();
fout.close();
}
}

}
這里完整的解壓代碼。
// if (!entry.getName().endsWith(file)) {
// continue;
// }
這段打開就是只解出一個你指定的文件。

下面是測試用的。
public static void main(String[] args) throws Exception {
new CommonFiles().unzip(new File("D:\\"), new File("D:\\test.zip"),"file.txt");
}

這個例子會在D盤生成型個test文件夾,file.txt就會在裡面,(裡面也可能會有多個文件夾,這個取決於壓縮包里文件的度)

④ 怎樣用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();
}
}
}

⑤ zip的文件,怎麼解壓縮打開

zip格式用手機怎麼打開是很多朋友關注的話題,其實zip格式的文件是一種經過壓縮的文件,通過壓縮之後,文件的體積會變小,從而更有利於在網路上傳播。經過壓縮的文件,如果想要再次使用,就必須通過解壓縮後才能使用,下面不妨就跟著小編一起去看看zip格式用手機如何打開吧。

以上就是ip格式用手機如何打開的具體介紹和操作方法了,希望可以幫助到你哦。

⑥ java怎麼讀取Zip和RAR裡面的文件啊

ZipInputStream是一個指向ZIP文件的流,這個流最重要的方法就是getNextEntry方法,一個zip文件可以包含好幾個被壓縮的文件,這個方法的功能就是返回下一個目錄項,也就是返回zip文件中的下一項,並且把流指向這個目錄文件項。getNextEntry的返回值是ZipEntry,它表示zip文件中的一個項,它可以返回這個文件項的大小、名稱等。你可以根據它返回的文件大小調用ZipInputStream的read方法來讀取需要的位元組。給你一個例子:public class ZipTest {
public static void main(String args[]) throws FileNotFoundException, IOException{
ZipInputStream zis = new ZipInputStream(new FileInputStream ("c://a.zip"));//生成讀取ZIP文件的流
ZipEntry ze = zis.getNextEntry();//取得下一個文件項
long size = ze.getSize();//取得這一項的大小
FileOutputStream fos = new FileOutputStream("c://"+ze.getName());//產生輸出文件對象
for(int i= 0;i<size;i++){//循環讀取文件並寫入輸出文件對象
byte c = (byte)zis.read();
fos.write(c);
}
fos.close();
zis.close();
}
}

⑦ 如何在java中實現對zip和rar文件的解壓

java中有zip包,可以使用

publicvoidgetZipFiles(StringzipFile,StringdestFolder)throwsIOException{
BufferedOutputStreamdest=null;
ZipInputStreamzis=newZipInputStream(
newBufferedInputStream(
newFileInputStream(zipFile)));
ZipEntryentry;
while((entry=zis.getNextEntry())!=null){
System.out.println("Extracting:"+entry.getName());
intcount;
bytedata[]=newbyte[BUFFER];

if(entry.isDirectory()){
newFile(destFolder+"/"+entry.getName()).mkdirs();
continue;
}else{
intdi=entry.getName().lastIndexOf('/');
if(di!=-1){
newFile(destFolder+"/"+entry.getName()
.substring(0,di)).mkdirs();
}
}
FileOutputStreamfos=newFileOutputStream(destFolder+"/"
+entry.getName());
dest=newBufferedOutputStream(fos);
while((count=zis.read(data))!=-1)
dest.write(data,0,count);
dest.flush();
dest.close();
}
}

rar的只能用第三方api,比如junrar

https://github.com/edmund-wagner/junrar

⑧ java中怎麼用cmd命令解壓zip文件

對於zip文件,java有自帶類庫java.util.zip;可是要想解壓rar文件只能靠第三方類庫,我試過兩個:com.github.junrar和de.innosystec.unrar,前者解壓時可能會出現crcError,後者pom配置時報錯;利用cmd命令調用winRAR進行解壓,無疑方便快捷很多。

調用cmd命令

public static boolean exe(String cmd) {
Runtime runtime = Runtime.getRuntime(); try {
Process p = runtime.exec(cmd);
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream(),"GBK"));

String line = reader.readLine(); while(line!=null) {
logger.info(line);
line = reader.readLine();
}
reader.close(); if(p.waitFor()!=0) { return false;
}
} catch (IOException e) { // TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) { // TODO Auto-generated catch block
e.printStackTrace();
} return true;
}

首先利用runtime.exec()執行指令,得到process,從process.getInputStream()中獲取回顯字元並列印,列印回顯時可能會出現中文亂碼,這個和操作系統編碼有關,我這里是GBK編碼,所以在new inputstreamReader時加入了編碼參數」GBK「

命令行字元串

如果需要調用cmd命令,如cd等,可寫」cmd c cd 目錄」。對於直接調用exe執行,則可以寫成」exe文件絕對路徑 參數」,在命令行字元串中,含有空格的路徑或者字元串應該再加上引號,即」」exe文件絕對路徑」 」參數」「

winRAR調用

我這里安裝目錄是C:/Program Files/WinRAR,將D:1.rar 解壓到D:,則寫成」」C:/Program Files/WinRAR/unRar.exe」 x -y D:/1.rar D:/」,x代表絕對路徑解壓,-y表示全部確定;壓縮的命令如下:「」C:/Program Files/WinRAR/rar.exe」 a -ep1 D:2.rar D:源目錄」,a表示添加文件到壓縮文件,-ep1表示排除基本目錄,如D:winrar ar這個目錄,如果沒有-ep1那麼壓縮包中會出現winrar目錄路徑,而加了之後就只將當前目錄打包,只有rar目錄

⑨ java如何解壓一個ZIP壓縮過的數據

1樓的方法。先解壓開後,你再把文件讀成流,把數據存資料庫

⑩ java如何直接解壓zip格式二進制流

Java代碼
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;

class ZipTest {
// 壓縮
public static void zip(String zipFileName, String inputFile)
throws Exception {
File f = new File(inputFile);
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(
zipFileName));
zip(out, f, f.getName());
System.out.println("zip done");
out.close();

閱讀全文

與javazip壓縮的文件怎麼打開相關的資料

熱點內容
壓縮包製作後照片順序怎麼改 瀏覽:680
fibonacci數列演算法 瀏覽:775
產品經理要和程序員吵架嗎 瀏覽:252
grub2命令行 瀏覽:618
無法獲取加密卡信息 瀏覽:774
雲伺服器網卡充值 瀏覽:509
編程就是軟體 瀏覽:49
伺服器如何添加許可權 瀏覽:437
引用指針編程 瀏覽:851
手機加密日記本蘋果版下載 瀏覽:63
命令行括弧 瀏覽:176
java程序升級 瀏覽:490
排序演算法之插入類 瀏覽:227
gcccreate命令 瀏覽:73
海爾監控用什麼app 瀏覽:64
系統盤被壓縮開不了機 瀏覽:984
linuxredis30 瀏覽:541
狸窩pdf轉換器 瀏覽:697
ajax調用java後台 瀏覽:906
活塞式壓縮機常見故障 瀏覽:615