导航:首页 > 编程语言 > java压缩数据

java压缩数据

发布时间:2023-06-02 11:03:57

java中的压缩原理是什么

什么是压缩文件? 简单的说,就是经过压缩软件压缩的文件叫压缩文件,压缩的原理是把文件的二进制代码压缩,把相邻的0,1代码减少,比如有000000,可以把它变成6个0 的写法60,来减少该文件的空间。 ■怎么压缩文件? 首先要安装压缩软件,现在比较流行的是WinRAR“一种高效快速的文件压缩软件(中文版)”。 其次是建立一个压缩包:选择你要制作成压缩包的文件或文件夹,当然你也可也多选,方法同资源管理器,也就是按住Ctrl或Shift再选择文件(文件夹)。 选取完毕之后,就可以单击工具栏上的“压缩”按钮,在这里你可以选择压缩格式:RAR和ZIP。 如果你想得到较大的压缩率,建议选择RAR格式。 各个选项选择好以后,单击确定按钮就开始制作压缩包了,非常方便。有时候大家会遇到这个问题,就是你在一个论坛里要上传一些文件压缩包,压缩包大小有3M,但是论坛限制会员上传大小只有2M,怎么办呢? 其实办法很简单,就是在你压缩这个文件时,分成几个带分卷压缩包,分卷包大小设置为2M即可,比如:原来文件名为123.rar(3M),压缩成分卷包后为123.part1.rar(2M)与123.part2.rar(1M)两个文件,这样你就可以上传了。 具体方法如下: 1、在要压缩的文件上点右键 2、添加到压缩文件.... 3、选常规 4、压缩方式选最好 5、批定压缩分卷大小(按字节计算),1M = 1024K,1K = 1024字节,填写数字即可 当你下载了带有分卷的压缩包后,如何解压文件呢? 具体方法如下: 1、把所有的压缩分卷全部下载完整 2、所有分卷必须在同一个文件夹内 3、然后双击解压第一个分卷,即可 注:分卷解压的文件必须是连续的,若分卷未下载完整,则解压时自然会提示需要下一压缩分卷

㈡ 用java如何实现压缩字符串

package javase1.day02;
/**
* 1)一种字符串压缩算法
* str ="aaaabbccccddeaaa"
* 压缩为:"4a2b4c2d1e3a"
* 原理实现:
* str = "aaaabbccccddeaaa"
*
* c = str.charAt(i)//c是每个字符
* 1) 初始化
* StringBuilder buf = new StringBuilder();
* int count = 0;代表相同的字符个数
* char ch = str.charAt(0);代表正在统计的相同字符'a'
* 2) 从i=1开始迭代每个字符
* c = str.charAt(i);//c是每个当前字符
* 3) 检查当前字符c与被统计ch是否一致
* 如果一致 count++
* 否则(不一致)
* 向缓冲区buf增加count+ch
* count=0,ch=c;
* 3)没有下个字符就结束
* 4)还有字符串吗?回到2)
*
* 2)实现还原算法
* str = "4a2b4c2d1e3a";
* i
*/
public class Demo5 {
public static void main(String[] args) {
String s = comp("aaaawwwwe");
System.out.println(s);
// System.out.println(decomp(s));

}
public static String comp(String str){
int i = 1;
StringBuilder buf = new StringBuilder();
int count = 1;
char ch = str.charAt(0);
for(;;){
char c = i==str.length() ? '\10':str.charAt(i);
if(c==ch){
count++;
}else{
if(count == 1)
buf.append(ch);
else
buf.append(count).append(ch);
count=1;
ch = c;
}
i++;
if(i==str.length()+1){
break;
}
}
return buf.toString();

}
}

㈢ JAVA 压缩和序列化

压缩和序列化主要用在数据的存储和传输上,二者都是由IO流相关知识实现,这里统一介绍下。

全部章节传送门:

Java I/O类支持读写压缩格式的数据流,你可以用他们对其他的I/O流进行封装,以提供压缩功能。

GZIP接口比较简单,适合对单个数据流进行压缩,在Linux系统中使用较多。

ZIP格式可以压缩多个文件,而且可以和压缩工具进行协作,是经常使用的压缩方法。

JAR(Java Archive,Java 归档文件)是与平台无关的文件格式,它允许将许多文件组合成一个压缩文件。为 J2EE 应用程序创建的 JAR 文件是 EAR 文件(企业 JAR 文件)。

JAR 文件格式以流行的 ZIP 文件格式为基础。与 ZIP 文件不同的是,JAR 文件不仅用于压缩和发布,而且还用于部署和封装库、组件和插件程序,并可被像编译器和 JVM 这样的工具直接使用。在 JAR 中包含特殊的文件,如 manifests 和部署描述符,用来指示工具如何处理特定的 JAR。

如果一个Web应用程序的目录和文件非常多,那么将这个Web应用程序部署到另一台机器上,就不是很方便了,我们可以将Web应用程序打包成Web 归档(WAR)文件,这个过程和把Java类文件打包成JAR文件的过程类似。利用WAR文件,可以把Servlet类文件和相关的资源集中在一起进行发布。在这个过程中,Web应用程序就不是按照目录层次结构来进行部署了,而是把WAR文件作为部署单元来使用。

一个WAR文件就是一个Web应用程序,建立WAR文件,就是把整个Web应用程序(不包括Web应用程序层次结构的根目录)压缩起来,指定一个.war扩展名。下面我们将第2章的Web应用程序打包成WAR文件,然后发布

要注意的是,虽然WAR文件和JAR文件的文件格式是一样的,并且都是使用jar命令来创建,但就其应用来说,WAR文件和JAR文件是有根本区别的。JAR文件的目的是把类和相关的资源封装到压缩的归档文件中,而对于WAR文件来说,一个WAR文件代表了一个Web应用程序,它可以包含 Servlet、HTML页面、Java类、图像文件,以及组成Web应用程序的其他资源,而不仅仅是类的归档文件。

在命令行输入jar即可查看jar命令的使用方法。

把对象转换为字节序列的过程称为对象的序列化。把字节序列恢复为对象的过程称为对象的反序列化。

对象的序列化主要有两种用途:

java.io.ObjectOutputStream代表对象输出流,它的writeObject(Object obj)方法可对参数指定的obj对象进行序列化,把得到的字节序列写到一个目标输出流中。

java.io.ObjectInputStream代表对象输入流,它的readObject()方法从一个源输入流中读取字节序列,再把它们反序列化为一个对象,并将其返回。

只有实现了Serializable的对象才能被序列化。对象序列化包括如下步骤:

对象反序列化的步骤如下:

创建一个可以可以序列化的对象。

然后进行序列化和反序列化测试。

s​e​r​i​a​l​V​e​r​s​i​o​n​U​I​D​:​ ​字​面​意​思​上​是​序​列​化​的​版​本​号​,凡是实现Serializable接口的类都有一个表示序列化版本标识符的静态变量。

JAVA序列化的机制是通过判断类的serialVersionUID来验证的版本一致的。在进行反序列化时,JVM会把传来的字节流中的serialVersionUID于本地相应实体类的serialVersionUID进行比较。如果相同说明是一致的,可以进行反序列化,否则会出现反序列化版本一致的异常,即是InvalidCastException。

为了提高serialVersionUID的独立性和确定性,强烈建议在一个可序列化类中显示的定义serialVersionUID,为它赋予明确的值。

控制序列化字段还可以使用Externalizable接口替代Serializable借口。此时需要定义一个默认构造器,否则将为得到一个异常(java.io.InvalidClassException: Person; Person; no valid constructor);还需要定义两个方法(writeExternal()和readExternal())来控制要序列化的字段。

如下为将Person类修改为使用Externalizable接口。

transient修饰符仅适用于变量,不适用于方法和类。在序列化时,如果我们不想序列化特定变量以满足安全约束,那么我们应该将该变量声明为transient。执行序列化时,JVM会忽略transient变量的原始值并将默认值(引用类型就是null,数字就是0)保存到文件中。因此,transient意味着不要序列化。

静态变量不是对象状态的一部分,因此它不参与序列化。所以将静态变量声明为transient变量是没有用处的。

㈣ java编程:数据压缩规则

你是不是问如何编写一个程序来压缩数据?如果你是想解决这个问题的话,继续往下看,如果你只是想要应付考试的话就算了。

—— 分割线

JDK本身提供了数据压缩的一个API

java.util.zip.Deflater.deflateBytes(byte[] b, int off, int len)

以下是我使用的一个例子,有点多,注释看不懂可以问我,不知道怎么用可以问我,其他的就算了。

/**
* threshold value for compress
*/
public static final int THRESHOLD = 1200;

/**
* Answer a byte array compressed in the DEFLATER format from bytes.
*
* @param bytes
* a byte array
* @return byte[] compressed bytes
* @throws IOException
*/
public static byte[] compress(byte[] bytes)
{
// Create the compressor with highest level of compression
Deflater compressor = new Deflater();
compressor.setLevel(Deflater.BEST_COMPRESSION);

// Give the compressor the data to compress
compressor.setInput(bytes);
compressor.finish();

// Create an expandable byte array to hold the compressed data.
// You cannot use an array that's the same size as the orginal because
// there is no guarantee that the compressed data will be smaller than
// the uncompressed data.
ByteArrayOutputStream bos = new ByteArrayOutputStream(bytes.length);

// Compress the data
byte[] buf = new byte[1024];
while (!compressor.finished())
{
int count = compressor.deflate(buf);
bos.write(buf, 0, count);
}
try
{
bos.close();
}
catch (IOException e)
{
}

// Get the compressed data
byte[] compressedData = bos.toByteArray();
return compressedData;
}

/**
* Answer a byte array that has been decompressed from the DEFLATER format.
*
* @param bytes
* a byte array
* @return byte[] compressed bytes
* @throws IOException
*/
public static byte[] uncompress(byte[] bytes)
{
// Create the decompressor and give it the data to compress
Inflater decompressor = new Inflater();
decompressor.setInput(bytes);

// Create an expandable byte array to hold the decompressed data
ByteArrayOutputStream bos = new ByteArrayOutputStream(bytes.length);

// Decompress the data
byte[] buf = new byte[1024];
while (!decompressor.finished())
{
try
{
int count = decompressor.inflate(buf);
bos.write(buf, 0, count);
}
catch (DataFormatException e)
{
}
}
try
{
bos.close();
}
catch (IOException e)
{
}

// Get the decompressed data
byte[] decompressedData = bos.toByteArray();
return decompressedData;
}

㈤ Java压缩与解压缩问题

/**
*类名:zipFileRelease
*说明:一个zip文件解压类
*介绍:主要的zip文件释放方法releaseHandle()
* 用ZipInputStream类和ZipEntry类将zip文件的入口清单列举出来,然后
* 根据用户提供的输出路径和zip文件的入口进行组合通过DataOutputStream
* 和File类进行文件的创建和目录的创建,创建文件时的文件数据是通过
* ZipInputStream类、ZipEntry类、InputStream类之间的套嵌组合获得的。
*注意:如果zip文件中包含中文路径程序将会抛出异常
*日期:2005-7-1
*作者:Pcera
*/

import java.io.*;
import java.util.*;
import java.util.zip.*;

class zipFileRelease{

private String inFilePath;
private String releaseFilePath;
private String[] FileNameArray; //存放文件名称的数组
private ZipEntry entry;
//
private FileInputStream fileDataIn;
private FileOutputStream fileDataOut;
private ZipInputStream zipInFile;
private DataOutputStream writeData;
private DataInputStream readData;
//
private int zipFileCount = 0; //zip文件中的文件总数
private int zipPathCount = 0; //zip文件中的路径总数

/**
*初始化函数
*初始化zip文件流、输出文件流以及其他变量的初始化
*/
public zipFileRelease(String inpath,String releasepath){
inFilePath = inpath;
releaseFilePath = releasepath;
}

/**
*初始化读取文件流函数
*参数:FileInputStream类
*返回值:初始化成功返回0,否则返回-1
*/
protected long initInStream(ZipInputStream zipFileA){
try{
readData = new DataInputStream(zipFileA);
return 0;
}catch(Exception e){
e.printStackTrace();
return -1;
}
}

/**
*测试文件路径
*参数:zip文件的路径和要释放的位置
*返回值:是两位整数,两位数中的十位代表输入路径和输出路径(1输入、2输出)
* 各位数是代表绝对路径还是相对路径(1绝对、0相对)
* 返回-1表示路径无效

protected long checkPath(String inPath,String outPath){
File infile = new File(inPath);
File infile = new File(outPath);

}
*/

/**
*初始化输出文件流
*参数:File类
*返回值:初始化成功返回0,否则返回-1
*/
protected long initOutStream(String outFileA){
try{
fileDataOut = new FileOutputStream(outFileA);
writeData = new DataOutputStream(fileDataOut);
return 0;
}catch(IOException e){
e.printStackTrace();
return -1;
}
}

/**
*测试文件是否存在方法
*参数:File类
*返回值:如果文件存在返回文件大小,否则返回-1
*/
public long checkFile(File inFileA){
if (inFileA.exists()){
return 0;
}else{
return -1;
}
}

/**
*判断文件是否可以读取方法
*参数:File类
*返回值:如果可以读取返回0,否则返回-1
*/
public long checkOpen(File inFileA){
if(inFileA.canRead()){
return inFileA.length();
}else{
return -1;
}
}

/**
*获得zip文件中的文件夹和文件总数
*参数:File类
*返回值:如果正常获得则返回总数,否则返回-1
*/
public long getFilFoldCount(String infileA){
try{
int fileCount = 0;
zipInFile = new ZipInputStream(new FileInputStream(infileA));
while ((entry = zipInFile.getNextEntry()) != null){
if (entry.isDirectory()){
zipPathCount++;
}else{
zipFileCount++;
}
fileCount++;
}
return fileCount;
}catch(IOException e){
e.printStackTrace();
return -1;
}
}

/**
*读取zip文件清单函数
*参数:File类
*返回值:文件清单数组
*/
public String[] getFileList(String infileA){
try{
ZipInputStream AzipInFile = new ZipInputStream(new FileInputStream(infileA));
//创建数组对象
FileNameArray = new String[(int)getFilFoldCount(infileA)];

//将文件名清单传入数组
int i = 0;
while ((entry = AzipInFile.getNextEntry()) != null){
FileNameArray[i++] = entry.getName();
}
return FileNameArray;
}catch(IOException e){
e.printStackTrace();
return null;
}
}

/**
*创建文件函数
*参数:File类
*返回值:如果创建成功返回0,否则返回-1
*/
public long writeFile(String outFileA,byte[] dataByte){
try{
if (initOutStream(outFileA) == 0){
writeData.write(dataByte);
fileDataOut.close();
return 0;
}else{
fileDataOut.close();
return -1;
}
}catch(IOException e){
e.printStackTrace();
return -1;
}
}

/**
*读取文件内容函数
*参数:File类
*返回值:如果读取成功则返回读取数据的字节数组,如果失败则返回空值
*/
protected byte[] readFile(ZipEntry entryA,ZipInputStream zipFileA){
try{
long entryFilelen;
if (initInStream(zipFileA) == 0){
if ((entryFilelen = entryA.getSize()) >= 0){
byte[] entryFileData = new byte[(int)entryFilelen];
readData.readFully(entryFileData,0,(int)entryFilelen);
return entryFileData;
}else{
return null;
}
}else{
return null;
}
}catch(IOException e){
e.printStackTrace();
return null;
}
}

/**
*创建目录函数
*参数:要创建目录的路径
*返回值:如果创建成功则返回0,否则返回-1
*/
public long createFolder(String dir){
File file = new File(dir);
if (file.mkdirs()) {
return 0;
}else{
return -1;
}
}

/**
*删除文件
*参数:要删除的文件
*返回值:如果删除成功则返回0,要删除的文件不存在返回-2
* 如果要删除的是个路径则返回-3,删除失败则返回-1
*/
public long deleteFile(String Apath) throws SecurityException {
File file = new File(Apath.trim());
//文件或路径不存在
if (!file.exists()){
return -2;
}
//要删除的是个路径
if (!file.isFile()){
return -3;
}
//删除
if (file.delete()){
return 0;
}else{
return -1;
}
}

/**
*删除目录
*参数:要删除的目录
*返回值:如果删除成功则返回0,删除失败则返回-1
*/
public long deleteFolder(String Apath){
File file = new File(Apath);
//删除
if (file.delete()){
return 0;
}else{
return -1;
}
}

/**
*判断所要解压的路径是否存在同名文件
*参数:解压路径
*返回值:如果存在同名文件返回-1,否则返回0
*/
public long checkPathExists(String AreleasePath){
File file = new File(AreleasePath);
if (!file.exists()){
return 0;
}else{
return -1;
}
}

/**
*删除zip中的文件
*参数:文件清单数组,释放路径
*返回值:如果删除成功返回0,否则返回-1
*/
protected long deleteReleaseZipFile(String[] listFilePath,String releasePath){
long arrayLen,flagReturn;
int k = 0;
String tempPath;
//存放zip文件清单的路径
String[] pathArray = new String[zipPathCount];
//删除文件
arrayLen = listFilePath.length;
for(int i=0;i<(int)arrayLen;i++){
tempPath = releasePath.replace('\\','/') + listFilePath[i];
flagReturn = deleteFile(tempPath);
if (flagReturn == -2){
//什么都不作
}else if (flagReturn == -3){
pathArray[k++] = tempPath;
}else if (flagReturn == -1){
return -1;
}
}
//删除路径
for(k = k - 1;k>=0;k--){
flagReturn = deleteFolder(pathArray[k]);
if (flagReturn == -1) return -1;
}
return 0;
}

/**
*获得zip文件的最上层的文件夹名称
*参数:zip文件路径
*返回值:文件夹名称,如果失败则返回null
*/
public String getZipRoot(String infileA){
String rootName;
try{
FileInputStream tempfile = new FileInputStream(infileA);
ZipInputStream AzipInFile = new ZipInputStream(tempfile);
ZipEntry Aentry;
Aentry = AzipInFile.getNextEntry();
rootName = Aentry.getName();
tempfile.close();
AzipInFile.close();
return rootName;
}catch(IOException e){
e.printStackTrace();
return null;
}
}

/**
*释放流,释放占用资源
*/
protected void closeStream() throws Exception{
fileDataIn.close();
fileDataOut.close();
zipInFile.close();
writeData.flush();
}

/**
*解压函数
*对用户的zip文件路径和解压路径进行判断,是否存在和打开
*在输入解压路径时如果输入"/"则在和zip文件存放的统计目录下进行解压
*返回值:0表示释放成功
* -1 表示您所要解压的文件不存在、
* -2表示您所要解压的文件不能被打开、
* -3您所要释放的路径不存在、
* -4您所创建文件目录失败、
* -5写入文件失败、
* -6表示所要释放的文件已经存在、
* -50表示文件读取异常
*/
public long releaseHandle() throws Exception{
File inFile = new File(inFilePath);
File outFile = new File(releaseFilePath);
String tempFile;
String zipPath;
String zipRootPath;
String tempPathParent; //存放释放路径
byte[] zipEntryFileData;

//作有效性判断
if (checkFile(inFile) == -1) {
return -1;}
if (checkOpen(inFile) == -1) {
return -2;}
//不是解压再当前目录下时对路径作有效性检验
if (!releaseFilePath.equals("/")){
//解压在用户指定目录下
if (checkFile(outFile) == -1) {
return -3;}
}
//获得标准释放路径
if (!releaseFilePath.equals("/")) {
tempPathParent = releaseFilePath.replace('\\','/')+ "/";
}else{
tempPathParent = inFile.getParent().replace('\\','/')+ "/";
}
//获得zip文件中的入口清单
FileNameArray = getFileList(inFilePath);
//获得zip文件的最上层目录
zipRootPath = getZipRoot(inFilePath);
//
fileDataIn = new FileInputStream(inFilePath);
zipInFile = new ZipInputStream(fileDataIn);
//判断是否已经存在要释放的文件夹
if (zipRootPath.lastIndexOf("/") > 0 ){
if (checkPathExists(tempPathParent +
zipRootPath.substring(0,zipRootPath.lastIndexOf("/"))) == -1){
return -6;
}
}else{
if (checkPathExists(tempPathParent + zipRootPath) == -1){
return -6;
}
}

//
try{
//创建文件夹和文件
int i = 0;
while ((entry = zipInFile.getNextEntry()) != null){
if (entry.isDirectory()){
//创建目录
zipPath = tempPathParent + FileNameArray[i];
zipPath = zipPath.substring(0,zipPath.lastIndexOf("/"));
if (createFolder(zipPath) == -1){
closeStream();
deleteReleaseZipFile(FileNameArray,tempPathParent);
return -4;
}

}else{
//读取文件数据
zipEntryFileData = readFile(entry,zipInFile);
//向文件写数据
tempFile = tempPathParent + FileNameArray[i];
//写入文件
if (writeFile(tempFile,zipEntryFileData) == -1){
closeStream();
deleteReleaseZipFile(FileNameArray,tempPathParent);
return -5;
}
}
i++;
}
//释放资源
closeStream();
return 0;
}catch(Exception e){
closeStream();
deleteReleaseZipFile(FileNameArray,tempPathParent);
e.printStackTrace();
return -50;
}
}
/**
*演示函数
*根据用户输入的路径对文件进行解压
*/
public static void main(String args[]) throws Exception {

long flag; //返回标志
String inPath,releasePath;

//获得用户输入信息
BufferedReader userInput = new BufferedReader(
new InputStreamReader(System.in));
System.out.println("请输入zip文件路径:");
inPath = userInput.readLine();
System.out.println("请输入保存路径:");
releasePath = userInput.readLine();
userInput.close();

//执行解压缩
zipFileRelease pceraZip = new zipFileRelease(inPath,releasePath);
flag = pceraZip.releaseHandle();

//出错信息打印
if (flag == 0) System.out.println("释放成功!!!");
if (flag == -1) System.out.println("您所要解压的文件不存在!");
if (flag == -2) System.out.println("您所要解压的文件不能被打开!");
if (flag == -3) System.out.println("您所要释放的路径不存在!");
if (flag == -4) System.out.println("您所创建文件目录失败!");
if (flag == -5) System.out.println("写入文件失败!");
if (flag == -6) System.out.println("文件已经存在!");
if (flag == -50) System.out.println("文件读取异常!");
}
}

㈥ 想用java做个压缩和解压缩的小程序,不知道如何实现。

root :释放文件路径 zipfile:待解压文件的路径 file:待解压文件的文件名
public 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();
}
}
}

㈦ java 如何压缩文件

楼主是说解压了的文件大小只有33.1MB,但是却占了51.2MB的空间吗?
如果是这个意思的话,那我要告诉楼主,首先这个问题和JAVA没有关系,根据你的截图,可以断定你用的是FAT32文件系统。这只是文件存储的形式,很正常。
简单的说,磁盘存储数据的最小单位是簇,比方说你的簇大小为128K,一个簇只能存放一个文件,然后你的一个文件只有16K,它占了这个簇,然后还有112K没有用,是吧。但是那112K就不能再存放其它文件了。如果要存放其它文件,就要占另一个簇。
楼主,懂了吧,这跟簇的大小有关,但是也不是簇越小越好,簇越小,读写性能都有所下降。这是正常现象。如果你非觉得不舒服,那就用NTFS文件系统吧,把压缩打开,就不会有这种情况了,希望对你有帮助

㈧ 如何使用JAVA代码压缩pdf文件

用java代码压缩应用到程序了,代码一般是比较复杂的,对pdf文件的mate标签优化,这类标签包括三类,pdf文件不是网页就是个文件,何况我们可以用pdf压缩工具压缩,下面有个解决方法,楼主可以做参照。

1:点击打开工具,打开主页面上有三个功能进行选择,我们选择pdf文件压缩。

㈨ java 如何压缩文件

楼主是说解压了的文件大小只有33.1MB,但是却占了51.2MB的空间吗?
如果是这个意思的话,那我要告诉楼主,首先这个问题和JAVA没有关系,根据你的截图,可以断定你用的是FAT32文件系统。这只是文件存储的形式,很正常。
简单的说,磁盘存储数据的最小单位是簇,比方说你的簇大小为128K,一个簇只能存放一个文件,然后你的一个文件只有16K,它占了这个簇,然后还有112K没有用,是吧。但是那112K就不能再存放其它文件了。如果要存放其它文件,就要占另一个簇。
楼主,懂了吧,这跟簇的大小有关,但是也不是簇越小越好,簇越小,读写性能都有所下降。这是正常现象。如果你非觉得不舒服,那就用NTFS文件系统吧,把压缩打开,就不会有这种情况了,希望对你有帮助

㈩ java将File压缩成zip

ZipOutputStream zos = new ZipOutputStream(new FileOutputStream("d:\\test.zip"));
String test1="test1";
String test2="test2";
byte[] bytes1 = test1.getBytes("UTF-8");
byte[] bytes2 = test2.getBytes("UTF-8");

ZipEntry z1 = new ZipEntry("test1.txt");
zos.putNextEntry(z1);
zos.write(bytes1);
ZipEntry z2 = new ZipEntry("text2.txt");
zos.putNextEntry(z2);
zos.write(bytes2);
zos.closeEntry();
zos.close();

//流可以自己获取

//java默认的包不支持中文(乱码)

//使用apache的ZipOutputStream进行zip压缩
是否可以解决您的问题?

阅读全文

与java压缩数据相关的资料

热点内容
露点外国电影 浏览:197
镇江服务器做棋牌游戏怎么样 浏览:855
uni小游戏源码 浏览:116
母乳在线母乳中出 浏览:783
鸿蒙为什么没有安卓彩蛋 浏览:997
可乐老师创意编程 浏览:28
七日杀如何设置专用服务器 浏览:28
主机怎么打开加密文件 浏览:19
重生收母系统小说 浏览:691
韩国电影静华 浏览:415
女的参加女儿运动会,下体塞了性爱玩具的电影 浏览:249
特警破案电影大全 浏览:443
学而思哪个app免费 浏览:972
孝敬爸妈电影介绍 浏览:94
软件编程前端月收入多少 浏览:983
在线网站78影院 浏览:587
发送接收邮件服务器是什么协议 浏览:737
印度电影有关蛇 浏览:449
广告公司asp源码 浏览:553
韩国电影在线观看韩国推理片推荐 浏览:229