导航:首页 > 文件处理 > 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压缩版相关的资料

热点内容
linuxcat与less 浏览:62
腾讯云轻量应用服务器初始端口 浏览:901
华为荣耀7x主题在哪个文件夹 浏览:330
linuxenv命令 浏览:861
android设置字体粗细 浏览:720
机场下载什么app有电子发票 浏览:531
python夹角余弦 浏览:658
格雷厄姆证券分析pdf 浏览:492
spf算法集成电路 浏览:674
一般程序员多少年薪 浏览:320
uggc工具箱源码 浏览:91
淘宝的文件夹怎么复制到微信 浏览:75
fputs函数php 浏览:307
怎么购买手机游戏源码 浏览:195
程序员分层怎么办 浏览:248
php检测编码 浏览:16
添加的光纤盒怎么加密 浏览:337
源码截图是什么 浏览:656
直销软件源码下载 浏览:894
固体液体很难被压缩 浏览:722