楼主是说解压了的文件大小只有33.1MB,但是却占了51.2MB的空间吗?
如果是这个意思的话,那我要告诉楼主,首先这个问题和JAVA没有关系,根据你的截图,可以断定你用的是FAT32文件系统。这只是文件存储的形式,很正常。
简单的说,磁盘存储数据的最小单位是簇,比方说你的簇大小为128K,一个簇只能存放一个文件,然后你的一个文件只有16K,它占了这个簇,然后还有112K没有用,是吧。但是那112K就不能再存放其它文件了。如果要存放其它文件,就要占另一个簇。
楼主,懂了吧,这跟簇的大小有关,但是也不是簇越小越好,簇越小,读写性能都有所下降。这是正常现象。如果你非觉得不舒服,那就用NTFS文件系统吧,把压缩打开,就不会有这种情况了,希望对你有帮助
‘贰’ tif文件太大怎么压缩
产品型号:ASUSS340MC‘叁’ Java如何把一个PDF转为tif
安装Office时,默认安装Microsoft Office Document Image Writer组件(没有重新添加),在Word中,选文件——打印——打印机选“Microsoft Office Document Image Writer”——属性——高级——输入格式选“TIFF-黑白传真”——设置默认输入的文件夹——确定——确定,打印完成后,将输出到刚设置的默认文件夹中。
‘肆’ java怎样压缩文件夹
压缩文件夹代码:
import java.io.File;
import org.apache.tools.zip.ZipOutputStream; //这个包在ant.jar里,要到官方网下载
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipEntry;
public class CompressBook {
public CompressBook() {}
/*
* inputFileName 输入一个文件夹
* zipFileName 输出一个压缩文件夹
*/
public void zip(String inputFileName) throws Exception {
String zipFileName = "c:\\test.zip"; //打包后文件名字
System.out.println(zipFileName);
zip(zipFileName, new File(inputFileName));
}
private void zip(String zipFileName, File inputFile) throws Exception {
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipFileName));
zip(out, inputFile, "");
System.out.println("zip done");
out.close();
}
private void zip(ZipOutputStream out, File f, String base) throws Exception {
if (f.isDirectory()) {
File[] fl = f.listFiles();
out.putNextEntry(new org.apache.tools.zip.ZipEntry(base + "/"));
base = base.length() == 0 ? "" : base + "/";
for (int i = 0; i < fl.length; i++) {
zip(out, fl[i], base + fl[i].getName());
}
}else {
out.putNextEntry(new org.apache.tools.zip.ZipEntry(base));
FileInputStream in = new FileInputStream(f);
int b;
System.out.println(base);
while ( (b = in.read()) != -1) {
out.write(b);
}
in.close();
}
}
public static void main(String [] temp){
CompressBook book = new CompressBook();
try {
book.zip("c:\\c");//你要压缩的文件夹
}catch (Exception ex) {
ex.printStackTrace();
}
}
}
‘伍’ java多线程压缩文件
public class Test{
public static void main(String args[])throws Exception{
File file = new File("D:\\Test.java");//Text文件
BufferedReader br = new BufferedReader(new FileReader(file));//构造一个BufferedReader类来读取文件
String s = null;
while((s = br.readLine())!=null){//使用readLine方法,一次读一行
System.out.println(s);
}
br.close();;
}
}
‘陆’ java 实现 tif图片(多页的)转换成jpg
多页单个tif文件转换为多个jpg文件
需要官方的一些包支持(具体参考源码),上网找找即可。
源码:
-------------------------
import java.io.*;
import com.sun.media.jai.codec.FileSeekableStream;
import com.sun.media.jai.codec.ImageDecoder;
import com.sun.media.jai.codec.ImageCodec;
import com.sun.media.jai.codec.TIFFEncodeParam;
import com.sun.media.jai.codec.TIFFDecodeParam;
import com.sun.media.jai.codec.JPEGEncodeParam;
import java.awt.image.RenderedImage;
import javax.media.jai.RenderedOp;
import javax.media.jai.JAI;
import java.awt.image.renderable.ParameterBlock;
public class MultiPageRead {
public static void main(String[] args) throws IOException {
new MultiPageRead().doitJAI();
}
public void doitJAI() throws IOException {
FileSeekableStream ss = new FileSeekableStream("./zhaoming.tif");
TIFFDecodeParam param0 = null;
TIFFEncodeParam param = new TIFFEncodeParam();
JPEGEncodeParam param1 = new JPEGEncodeParam();
ImageDecoder dec = ImageCodec.createImageDecoder("tiff", ss, param0);
int count = dec.getNumPages();
param.setCompression(TIFFEncodeParam.COMPRESSION_GROUP4);
param.setLittleEndian(false); // Intel
System.out.println("This TIF has " + count + " image(s)");
for (int i = 0; i < count; i++) {
RenderedImage page = dec.decodeAsRenderedImage(i);
File f = new File("./fk_" + i + ".jpg");
System.out.println("Saving " + f.getCanonicalPath());
ParameterBlock pb = new ParameterBlock();
pb.addSource(page);
pb.add(f.toString());
pb.add("JPEG");
pb.add(param1);
//JAI.create("filestore",pb);
RenderedOp r = JAI.create("filestore",pb);
r.dispose();
//RenderedOp op = JAI.create("filestore", page, "./zhaoming_" + i + ".jpg", "JPEG", param1);
}
}
}
‘柒’ 求助java压缩图片存储大小的方法
可以使用Draw这个类,通过改变像素来改变存储大小,实例如下:
(StringsrcFilePath,StringdescFilePath)throwsIOException{
Filefile=null;
BufferedImagesrc=null;
FileOutputStreamout=null;
ImageWriterimgWrier;
ImageWriteParamimgWriteParams;
//指定写图片的方式为jpg
imgWrier=ImageIO.getImageWritersByFormatName("jpg").next();
imgWriteParams=newjavax.imageio.plugins.jpeg.JPEGImageWriteParam(
null);
//要使用压缩,必须指定压缩方式为MODE_EXPLICIT
imgWriteParams.setCompressionMode(imgWriteParams.MODE_EXPLICIT);
//这里指定压缩的程度,参数qality是取值0~1范围内,
imgWriteParams.setCompressionQuality((float)1);
imgWriteParams.setProgressiveMode(imgWriteParams.MODE_DISABLED);
ColorModelcolorModel=ImageIO.read(newFile(srcFilePath)).getColorModel();//ColorModel.getRGBdefault();
//指定压缩时使用的色彩模式
//imgWriteParams.setDestinationType(newjavax.imageio.ImageTypeSpecifier(
//colorModel,colorModel.createCompatibleSampleModel(16,16)));
imgWriteParams.setDestinationType(newjavax.imageio.ImageTypeSpecifier(
colorModel,colorModel.createCompatibleSampleModel(16,16)));
try{
if(isBlank(srcFilePath)){
returnfalse;
}else{
file=newFile(srcFilePath);System.out.println(file.length());
src=ImageIO.read(file);
out=newFileOutputStream(descFilePath);
imgWrier.reset();
//必须先指定out值,才能调用write方法,ImageOutputStream可以通过任何
//OutputStream构造
imgWrier.setOutput(ImageIO.createImageOutputStream(out));
//调用write方法,就可以向输入流写图片
imgWrier.write(null,newIIOImage(src,null,null),
imgWriteParams);
out.flush();
out.close();
}
}catch(Exceptione){
e.printStackTrace();
returnfalse;
}
returntrue;
}
publicstaticbooleanisBlank(Stringstring){
if(string==null||string.length()==0||string.trim().equals("")){
returntrue;
}
returnfalse;
}
‘捌’ java读取压缩文件并压缩
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
public class JZip {
public static int iCompressLevel;//压缩比 取值范围为0~9
public static boolean bOverWrite;//是否覆盖同名文件 取值范围为True和False
@SuppressWarnings("unchecked")
private static ArrayList AllFiles = new ArrayList();
public static String sErrorMessage;
private String zipFilePath;
public List<File> srcMap;
public JZip () {
iCompressLevel = 9;
// bOverWrite=true;
}
public JZip(String zipFilePath) throws FileNotFoundException, IOException {
this.zipFilePath = zipFilePath;
}
@SuppressWarnings("unchecked")
public static ArrayList extract (String sZipPathFile , String sDestPath) {
ArrayList AllFileName = new ArrayList();
try {
//先指定压缩档的位置和档名,建立FileInputStream对象
FileInputStream fins = new FileInputStream(sZipPathFile);
//将fins传入ZipInputStream中
ZipInputStream zins = new ZipInputStream(fins);
ZipEntry ze = null;
byte ch[] = new byte[256];
while ((ze = zins.getNextEntry()) != null) {
File zfile = new File(sDestPath + ze.getName());
File fpath = new File(zfile.getParentFile().getPath());
if (ze.isDirectory()) {
if (!zfile.exists())
zfile.mkdirs();
zins.closeEntry();
} else {
if (!fpath.exists())
fpath.mkdirs();
FileOutputStream fouts = new FileOutputStream(zfile);
int i;
AllFileName.add(zfile.getAbsolutePath());
while ((i = zins.read(ch)) != -1)
fouts.write(ch, 0, i);
zins.closeEntry();
fouts.close();
}
}
fins.close();
zins.close();
sErrorMessage = "OK";
} catch (Exception e) {
System.err.println("Extract error:" + e.getMessage());
sErrorMessage = e.getMessage();
}
AllFiles.clear();
return AllFileName;
}
@SuppressWarnings({ "unchecked", "static-access" })
public static void compress (String sPathFile , boolean bIsPath , String sZipPathFile) {
try {
String sPath;
//先指定压缩档的位置及档名,建立一个FileOutputStream
FileOutputStream fos = new FileOutputStream(sZipPathFile);
//建立ZipOutputStream并将fos传入
ZipOutputStream zos = new ZipOutputStream(fos);
//设置压缩比
zos.setLevel(iCompressLevel);
if (bIsPath == true) {
searchFiles(sPathFile);
sPath = sPathFile;
} else {
File myfile = new File(sPathFile);
sPath = sPathFile.substring(0, sPathFile.lastIndexOf(myfile.separator) + 1);
AllFiles.add(myfile);
}
Object[] myobject = AllFiles.toArray();
ZipEntry ze = null;
//每个档案要压缩,都要透过ZipEntry来处理
FileInputStream fis = null;
BufferedReader in = null;
//byte[] ch = new byte[256];
for (int i = 0 ; i < myobject.length ; i++) {
File myfile = (File) myobject[i];
if (myfile.isFile()) {
in = new BufferedReader(new InputStreamReader(new FileInputStream(myfile.getPath()),"iso8859-1"));
//以档案的名字当Entry,也可以自己再加上额外的路径
//例如ze=new ZipEntry("test\\"+myfiles[i].getName());
//如此压缩档内的每个档案都会加test这个路径
ze = new ZipEntry(myfile.getPath().substring((sPath).length()));
//将ZipEntry透过ZipOutputStream的putNextEntry的方式送进去处理
fis = new FileInputStream(myfile);
zos.putNextEntry(ze);
int len = 0;
//开始将原始档案读进ZipOutputStream
while ((len = in.read()) != -1) {
zos.write(len);
}
fis.close();
zos.closeEntry();
}
}
zos.close();
fos.close();
AllFiles.clear();
sErrorMessage = "OK";
} catch (Exception e) {
System.err.println("Compress error:" + e.getMessage());
sErrorMessage = e.getMessage();
}
}
/*
这是一个递归过程,功能是检索出所有的文件名称
dirstr:目录名称
*/
@SuppressWarnings("unchecked")
private static void searchFiles (String dirstr) {
File tempdir = new File(dirstr);
if (tempdir.exists()) {
if (tempdir.isDirectory()) {
File[] tempfiles = tempdir.listFiles();
for (int i = 0 ; i < tempfiles.length ; i++) {
if (tempfiles[i].isDirectory())
searchFiles(tempfiles[i].getPath());
else {
AllFiles.add(tempfiles[i]);
}
}
} else {
AllFiles.add(tempdir);
}
}
}
public String getZipFilePath() {
return zipFilePath;
}
public void setZipFilePath(String zipFilePath) {
this.zipFilePath = zipFilePath;
}
/**
* 解析zip文件得到文件名
* @return
* @throws FileNotFoundException
* @throws IOException
*/
public boolean parserZip() throws FileNotFoundException, IOException {
FileInputStream fis = new FileInputStream(zipFilePath);
ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis));
ZipEntry entry;
try {
srcMap = new ArrayList<File>();
while ((entry = zis.getNextEntry()) != null) {
File file = new File(zipFilePath + File.separator + entry.getName());
srcMap.add(file);
}
zis.close();
fis.close();
return true;
} catch (IOException e) {
return false;
}
}
/**
*
* @param zipFileName 待解压缩的ZIP文件
* @param extPlace 解压后的文件夹
*/
public static void extZipFileList(String zipFileName, String extPlace) {
try {
ZipInputStream in = new ZipInputStream(new FileInputStream(
zipFileName));
File files = new File(extPlace);
files.mkdirs();
ZipEntry entry = null;
while ((entry = in.getNextEntry()) != null) {
String entryName = entry.getName();
if (entry.isDirectory()) {
File file = new File(files + entryName);
file.mkdirs();
System.out.println("创建文件夹:" + entryName);
} else {
OutputStream os = new FileOutputStream(files+File.separator + entryName);
// Transfer bytes from the ZIP file to the output file
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
os.write(buf, 0, len);
}
os.close();
in.closeEntry();
System.out.println("解压文件:" + entryName);
}
}
} catch (IOException e) {
}
}
@SuppressWarnings("static-access")
public static void main(String args[]){
}
}
‘玖’ 怎样缩小TIFF格式图片的大小
1、还可以更改照片的格式,JPG<BMP<GIF<PSD,要改变大小的时候,可以将照片的格式改为JPG。在电脑画图中打开图片,选择“另存为”。
‘拾’ java如何实现多个文件的压缩
importjava.util.*;
importjava.net.URI;
importjava.nio.file.Path;
importjava.nio.file.*;
publicclassZipFSPUser{
publicstaticvoidmain(String[]args)throwsThrowable{
Map<String,String>env=newHashMap<>();
env.put("create","true");
//
//definedinjava.net.JarURLConnection
URIuri=URI.create("jar:file:/codeSamples/zipfs/zipfstest.zip");
try(FileSystemzipfs=FileSystems.newFileSystem(uri,env)){
PathexternalTxtFile=Paths.get("/codeSamples/zipfs/SomeTextFile.txt");
PathpathInZipfile=zipfs.getPath("/SomeTextFile.txt");
//afileintothezipfile
Files.(externalTxtFile,pathInZipfile,
StandardCopyOption.REPLACE_EXISTING);
}
}
}
创建一个zip文件,并添加一个文件进去,需要JDK7