/**
* Program to Unzip a file content to a text file using try-with-resource feature.
*/
public class ReadAZipFile
{
/** Pass, the outputfilename and zipFilename in args[] array when executed **/
public static void main(String args[]) throws Exception {
java.nio.charset.Charset charset =
java.nio.charset.StandardCharsets.US_ASCII;
java.nio.file.Path outputFilePath =
java.nio.file.Paths.get(args[0]);
try (
java.util.zip.ZipFile zipfile =
new java.util.zip.ZipFile(args[1]);
java.io.BufferedWriter writer =
java.nio.file.Files.newBufferedWriter(outputFilePath, charset)
) {
for (java.util.Enumeration entries =
zipfile.entries(); entries.hasMoreElements();) {
String newLineSeperator = System.getProperty("line.separator");
String zipEntryName =
((java.util.zip.ZipEntry)entries.nextElement()).getName() +
newLineSeperator;
writer.write(zipEntryName, 0, zipEntryName.length());
}
}
}
}
* Program to Unzip a file content to a text file using try-with-resource feature.
*/
public class ReadAZipFile
{
/** Pass, the outputfilename and zipFilename in args[] array when executed **/
public static void main(String args[]) throws Exception {
java.nio.charset.Charset charset =
java.nio.charset.StandardCharsets.US_ASCII;
java.nio.file.Path outputFilePath =
java.nio.file.Paths.get(args[0]);
try (
java.util.zip.ZipFile zipfile =
new java.util.zip.ZipFile(args[1]);
java.io.BufferedWriter writer =
java.nio.file.Files.newBufferedWriter(outputFilePath, charset)
) {
for (java.util.Enumeration entries =
zipfile.entries(); entries.hasMoreElements();) {
String newLineSeperator = System.getProperty("line.separator");
String zipEntryName =
((java.util.zip.ZipEntry)entries.nextElement()).getName() +
newLineSeperator;
writer.write(zipEntryName, 0, zipEntryName.length());
}
}
}
}
No comments:
Post a Comment