我知道如何创建zip存档:
import java.io.*;
import java.util.zip.*;
public class ZipCreateExample{
public static void main(String[] args) throws Exception
// input file
FileInputStream in = new FileInputStream("F:/sometxt.txt");
// out put file
ZipOutputStream out = new ZipOutputStream(new FileOutputStream("F:/tmp.zip"));
// name the file inside the zip file
out.putNextEntry(new ZipEntry("zippedjava.txt"));
// buffer size
byte[] b = new byte[1024];
int count;
while ((count = in.read(b)) > 0) {
System.out.println();
out.write(b, 0, count);
}
out.close();
in.close();
}
}
Run Code Online (Sandbox Code Playgroud)
但我不知道如何使用lzma压缩.
我找到了这个项目:https://github.com/jponge/lzma-java,它创建压缩文件,但我不知道如何将它与我现有的解决方案结合起来.
你提到的网站上有一个例子:
适应您的需求:
final File sourceFile = new File("F:/sometxt.txt");
final File compressed = File.createTempFile("lzma-java", "compressed");
final LzmaOutputStream compressedOut = new LzmaOutputStream.Builder(
new BufferedOutputStream(new FileOutputStream(compressed)))
.useMaximalDictionarySize()
.useEndMarkerMode(true)
.useBT4MatchFinder()
.build();
final InputStream sourceIn = new BufferedInputStream(new FileInputStream(sourceFile));
IOUtils.copy(sourceIn, compressedOut);
sourceIn.close();
compressedOut.close();
Run Code Online (Sandbox Code Playgroud)
(我不知道它是否有效,这只是库和您的代码片段的用法)
| 归档时间: |
|
| 查看次数: |
4482 次 |
| 最近记录: |