Live Webinar: Prompt Engineering: Skill Everyone Must Learn Today
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Zip the File in Java Program
WhatsApp
Alagunila Meganathan
Aug 03
2016
566
0
0
JavaUncompress.rar
import
java.util.zip.GZIPInputStream;
import
java.io.OutputStream;
import
java.io.FileOutputStream;
import
java.io.FileInputStream;
import
java.io.FileNotFoundException;
import
java.io.IOException;
public
class
JavaUncompress{
public
static
void
main(String args[]){
try
{
//To Uncompress GZip File Contents we need to open the gzip file.....
if
(args.length<=
0
){
System.out.println(
"Please enter the valid file name"
);
}
else
{
String inFilename = args[
0
];
System.out.println(
"Opening the gzip file.......................... : opened"
);
GZIPInputStream gzipInputStream =
null
;
FileInputStream fileInputStream =
null
;
gzipInputStream =
new
GZIPInputStream(
new
FileInputStream(inFilename));
System.out.println(
"Opening the output file............. : opened"
);
String outFilename = inFilename +
".pdf"
;
OutputStream out =
new
FileOutputStream(outFilename);
System.out.println(
"Trsansferring bytes from the compressed file to the output file........: Transfer successful"
);
byte
[] buf =
new
byte
[
1024
];
//size can be changed according to programmer's need.
int
len;
while
((len = gzipInputStream.read(buf)) >
0
) {
out.write(buf,
0
, len);
}
System.out.println(
"The file and stream is ......closing.......... : closed"
);
gzipInputStream.close();
out.close();
}
}
catch
(IOException e){
System.out.println(
"Exception has been thrown"
+ e);
}
}
}
Java
Up Next
Zip the File in Java Program