Buyuknet

Bilgisayar Dünyası => Programlama Dilleri => Webmaster => Java => Konuyu başlatan: tarantula901 - 17.11.2013 - 18:14

Başlık: Java Dosya sıkıştırma - java dosya açma kodları
Gönderen: tarantula901 - 17.11.2013 - 18:14
Dosya sıkıştırma:

Kod: [Seç]
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.DeflaterOutputStream;

public class Deflate {
    public static void main(String[] args) throws FileNotFoundException, IOException{
    FileInputStream fin = new FileInputStream(args[0]);
    FileOutputStream fos = new FileOutputStream(args[0] + ".def");
    DeflaterOutputStream dos = new DeflaterOutputStream(fos);
    byte[] buffer = new byte[256];
    int numberRead;

    while ( (numberRead = fin.read(buffer)) >= 0 ){
        dos.write(buffer, 0, numberRead);
    }
    dos.close();
    fin.close();
 }
}

Dosya açma:

Kod: [Seç]
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.InflaterInputStream;

public class Inflate{
   public static void main(String[] args) throws FileNotFoundException, IOException{
    String subFile = null;

    FileInputStream fin = new FileInputStream(args[0]);
    InflaterInputStream iis = new InflaterInputStream(fin);

    if (args[0].endsWith(".def")){
        int lastDot = args[0].lastIndexOf('.');
        subFile = args[0].substring(0,lastDot);
    }

    FileOutputStream fos = new FileOutputStream(subFile);

    byte[] buffer = new byte[256];
    int numberRead;

    while ( (numberRead = iis.read(buffer)) >= 0 ){
        fos.write(buffer, 0, numberRead);
    }
   iis.close();
   fos.close();
 }
}