-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompressFile.java
More file actions
39 lines (31 loc) · 842 Bytes
/
CompressFile.java
File metadata and controls
39 lines (31 loc) · 842 Bytes
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
31
32
33
34
35
36
37
38
39
/**
*
*/
package filesIO;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.GZIPOutputStream;
/**
* @author rutpatel
*
*/
public class CompressFile {
public static void main(String[] args) {
try (FileInputStream fis = new FileInputStream(new File("src/filesIO/data.txt"));
GZIPOutputStream gos = new GZIPOutputStream(new FileOutputStream("src/filesIO/dataComp.gz"));) {
byte[] buff = new byte[1024];
int len;
while ((len = fis.read(buff)) > 0) {
gos.write(buff, 0, len);
}
System.out.println("File Compressed...dataComp.gz");
} catch (FileNotFoundException e) {
System.out.println(e.getMessage());
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
}