May 30, 2017

Compress folders/files and create .tar.gz (Tar archive with GunZip Compression) and .zip (ZIP compression) file in Java

Hi friends,

Today I will explain how easily we can compress files and folders in java.

I have used a third part library which so simple to use.

Download the .jar from the following URL
https://rauschig.org/jarchivelib/download.html

Now, create a java class and create .tar.gz and .zip files.

Sample source code

package gunziptest;

import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.rauschig.jarchivelib.ArchiveFormat;
import org.rauschig.jarchivelib.Archiver;
import org.rauschig.jarchivelib.ArchiverFactory;
import org.rauschig.jarchivelib.CompressionType;

/**
 *
 * @author psrdotcom
 */
public class GunZipTest {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // Archive file name
        String archiveName = "archive";
        // test is destination folder
        File destination = new File("test");
        // source folder has files and sub-folders
        File archive = null;
        
        // zip compression
        Archiver archiver = ArchiverFactory.createArchiver(ArchiveFormat.ZIP);
        try {
            archive = archiver.create(archiveName, destination, source);
            if(archive != null && archive.isFile()) {
                System.out.println("gunziptest.GunZipTest.main()" + "zip file created");
            }
        } catch (IOException ex) {
            Logger.getLogger(GunZipTest.class.getName()).log(Level.SEVERE, null, ex);
        }

        // tar.gz compression
        archiver = ArchiverFactory.createArchiver(ArchiveFormat.TAR, CompressionType.GZIP);
        try {
            archive = archiver.create(archiveName, destination, source);
            if(archive != null && archive.isFile()) {
                System.out.println("gunziptest.GunZipTest.main()" + "zip file created");
            }
        } catch (IOException ex) {
            Logger.getLogger(GunZipTest.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

Hope, you will find this useful.

Please send your review and feedback to psrdotcom@gmail.com

May 24, 2017

Prevent from WannaCry Ransome attack by disabling SMB protocol on Windows 10

Hi friends,

I want to share my knowledge on disabling SMB protocol on Windows 10.

Procedure


  1. Click on Start Menu
  2. Type "Turn Windows Features On or Off"
  3. Uncheck the "SMB 1.0/CIFS File Sharing Support" as shown below
  4. Click on "OK"
  5. It will take some time to apply the changes
  6. You will be prompted with "Restart"
  7. Save your any unsaved work and restart the machine
  8. This is disable the SMB protocol, which is main reason to spread the WannaCry Ransome Attack


Please send your review and feedback to psrdotcom@gmail.com

May 03, 2017

Eclipse reset/enable workspace preference on startup

Hi all,

Today, I have come across a situation where I want to choose the one of the workspaces i have worked before.

In general, eclipse will prompt for workspace location on startup
But, if you have checked "Consider this as default workspace and don't ask again" option, then next time when you start eclipse, you won't get the prompt for workspace selection.

Re-enable/Reset workspace preference on eclipse startup


  1. Click on eclipse "Window->Preferences"
  2. Go to "General->Startup/Shutdown->Workspaces"
  3. Check "Prompt for workspace on startup" or use keyboard shortcut "Alt+w" 
  4. Now, exit the eclipse
  5. Start the eclipse
You should be able to see the workspace selection on eclipse startup screen.

Happy coding!!

Please send your comments and feedback to psrdotcom@gmail.com

Featured Post

Java Introdcution

Please send your review and feedback to psrdotcom@gmail.com