Whenever I take any new project, I always require my Utilities library which provides me following features:
All this features can be achieved using just one library, and using this library is dam easy...even you can attach a listener to listen the processing i.e.
import fileutilslibrary.CopyEvent;
import fileutilslibrary.FileUtils;
import fileutilslibrary.Listener;
import fileutilslibrary.ZipEvent;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author Naved Momin<naved.spartans.rocks75@gmail.com>
*/
public class Demo2 implements Listener{
void start( ) throws IOException{
FileUtils.getInstance().addListener(this);
FileUtils.zipMyFolder(new File("C:\\Users\\Admin\\Desktop\\imgToVideo/RemoteDesktop"),
new File("C:/Users/Admin/Desktop/HMS Latest/RDnew.zip"),9);
}
public static void main(String[] args) {
try {
// TODO code application logic here
new Demo2().start();
} catch (IOException ex) {
Logger.getLogger(Demo2.class.getName()).log(Level.SEVERE, null, ex);
}
}
@Override
public void copyListener(CopyEvent e) {
//notification about copying event
}
@Override
public void zipListener(ZipEvent e) {
//notification about zip event
System.out.println( "name " +e.getZipingFileName() + "\n" + "size " + e.getZipingFileSize() + "\n" +
" count " + e.getFileCount( ) + "\n" +
"level " + e.getCompressionLevel() );
}
}
Various Methods:-
FileUtils.copyDirectory(src, dest);
Copy a File
FileUtils.copyFile(src, dest);
Zip Directory
FileUtils.zipMyFolder(src, dest);
Zip Directory With Custom Compression Level
FileUtils.zipMyFolder(src, dest, compressionLevel);
Note: Compression level must be between 0-9, by default 0 is used
Zip File
FileUtils.zipMyFile(src, dest);
Zip File With Custom Compression Level
FileUtils.zipMyFile(src, dest, compressionLevel);
Note: Compression level must be between 0-9, by default 0 is used
UnZip File
FileUtils.doUnZip(src, dest);
Get File Extension (10x faster)
FileUtils.getExtension(path);
Reverse a String
FileUtils.reverse(str);
Get File Name
FileUtils.getName(pathToFile);
Note: The library is written in pure Java code except the Wallpaper class which throws NotSupportedOSException if OS is not supported by the library for more information see Javadoc included in the download package.
This library is totally compatible with various 3rd party zip utilities like winrar, which means you can zip your files programmatically and still use winrar for unzip'ing the file or vice-versa is also possible.