kamagra vs viagra

Using Apache Commons IO

If you’d like to save time implementing various IO functionality such as ordinary file copy/directory delete operations, effective i/o streams, comparators and much more you may want to use Apache Commons IO library in your project.

Commons IO is a library of utilities to assist with developing IO functionality.

more info on: [...]

Java delete directory and contents

Solution for deleting directory with its contents:

public static void deleteDir(File f) throws Exception { if (f.isDirectory()) { for (File ff : f.listFiles()) deleteDir(ff); } if (!f.delete()) throw new Exception("Cannot delete file: " + f); }



Java copy files

Solution to copy a file from one location to another.

1) OLD way – before JDK1.4 import java.io.*; … … public static void copyFile(File srcFile, File destFile) throws Exception { FileInputStream src = new FileInputStream(srcFile); FileOutputStream dest = new FileOutputStream(destFile); try { byte[] buf = new byte[1024]; int i = 0; while ((i [...]

Java regex check ip address

Here is some code example how to check if an ip address is a valid ipv4 address using regular expressions:

package net.andwise.chkipregex; import java.util.regex.Matcher; import java.util.regex.Pattern; public class SampleClass{ … … private Pattern ipPattern; private Matcher ipMatcher; private static final String IPADDR_PATTERN = "^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])$"; … … public [...]

Get packages from IProject in eclipse using IJavaProject.

When working with Eclipse and especially when developing plug-ins you will deal with the org.eclipse.core.resources.IProject interface.

This however does not give you an option to get the packages used in the project. For that you will need org.eclipse.jdt.core.IJavaProject interface which is a completely different interface and cannot just get it from a cast [...]

Change default @author tag in Eclipse comments

We know that ‘Shift-Alt-J’ is quite useful to generate java docs.

By default when used with types it generates

/** * @author ${user} * * ${tags} */

So it gets your default ‘user’ variable.

You can change this template from window->preferences->Java->Code Style->Code Templates

However a neater way is to change your ${user} variable.