Posts Tagged ‘file’

How to decompress zip file in Java

September 30, 2013 Leave a comment

Introduce how to decompress a zip file in Java:

public void unzip(File zipFile, String outputFolder)
        byte[] buffer = new byte[1024];
        ZipEntry ze = null;
            File folder = new File(outputFolder);
            if (!folder.exists())
            ZipInputStream zis = new ZipInputStream(new BufferedInputStream(new FileInputStream(zipFile)));
            while ((ze = zis.getNextEntry()) != null)
                String fileName = ze.getName();
                File newFile = new File(outputFolder + File.separator + fileName);
                System.out.println("unziping : " + newFile.getAbsoluteFile());
                new File(newFile.getParent()).mkdirs();

                FileOutputStream fos = new FileOutputStream(newFile);

                int len;
                while ((len = > 0)
                    fos.write(buffer, 0, len);
        catch (Exception ex)
            if (zipFile != null)
                System.out.println("Do not decompress file " + zipFile.getName() + " (size: 0kb)!");
Categories: Java Tags: , , ,

Read and write a txt file in C#

In the case you want to read or write some short information from or into a text file, Csharp supports a simple way for you in System.IO.File. You create a text file in directory “C:\\config.txt” and then:
Read file
There are some lines in above file, and each line has its own meaning, so you need to read every line and write into a list or an array like this:

private void readFile()
    string[] lines = System.IO.File.ReadAllLines(@"C:\config.txt");
    //then you can convert every element of the array into the data you want

Write file
You have some information need to be stored in a text file, you can use the below function:

private void writeFile()
    string[] lines = { lstCube.Count.ToString(), numOfXRect.ToString(), count.ToString() };

Are they so simple,hihi, i just want to store in case i need.:D

Categories: C# Tags: , , ,
%d bloggers like this: