{{theTime}}

Search This Blog

Total Pageviews

Java Program to Unzip a file and Writing to a text file using try-with-resource feature

/**
 *  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:

Generate Insert Sql from Select Statement

SELECT 'INSERT INTO ReferenceTable (ID, Name) VALUES (' +        CAST(ID AS NVARCHAR) + ', ''' + Name + ''...