250x250
Notice
Recent Posts
Recent Comments
관리 메뉴

탁월함은 어떻게 나오는가?

[JAVA] 자바 압축하기 압축해제 사용법 본문

[Snow-ball]프로그래밍(컴퓨터)/java

[JAVA] 자바 압축하기 압축해제 사용법

Snow-ball 2021. 3. 5. 17:33
반응형
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package FourthClass_k;
 
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
 
// 압축해제 코드
 
public class ZipTest {
    public static void main(String[] args) throws IOException {
 
        FileInputStream fin = new FileInputStream("src/FourthClass_k/test.zip");
        ZipInputStream zin = new ZipInputStream(fin);
        // entry 사전적의미 : 입장하다.
        ZipEntry entry = null;
        while ((entry = zin.getNextEntry()) != null) {
            System.out.println("압축 해제: " + entry.getName());
            FileOutputStream fout = new FileOutputStream(entry.getName());
            for (int c = zin.read(); c != -1; c = zin.read()) {
                fout.write(c);
            }
            zin.closeEntry();
            fout.close();
        }
        zin.close();
    }
}
 
cs

 

 

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package FourthClass_k;
 
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
 
// 압축하기 코드
 
public class ZipTest2 {
    public static void main(String[] args) throws IOException {
        String outputFile = "src/FourthClass_k/test.zip";
        int level = 9;
        FileOutputStream fout = new FileOutputStream(outputFile);
        ZipOutputStream zout = new ZipOutputStream(fout);
        zout.setLevel(level);
 
        ZipEntry entry = new ZipEntry("src/FourthClass_k/input.txt");
        FileInputStream fin = new FileInputStream("src/FourthClass_k/input.txt");
        zout.putNextEntry(entry);
        for (int c = fin.read(); c != -1; c = fin.read()) {
            zout.write(c);
        }
        fin.close();
        zout.close();
    }
}
 
cs
반응형
Comments