Recent Articles / Archives

If folder depth more than 255 character

If you have your directory depth more than 255 characters as created in my previous article, file explorer e.g windows explorer will not be able to delete it showing error it has more length then expected or so. In order to delete those folders which has folder depth more than 255 character, copy paste the code below to your favorite editor, save it with the classname you wish, and change the directory mentioned in the code to the target root directory where you want to apply this repetitive deletion.

import java.io.File;
public class ThousandDirectory {
    public static void main(String[] args) {
        String abc = "D:\\ThousandDirectory";
        String onlyDirectory = "ThousandDirectory";
        File baseDirectory = new File(abc);
        try {
            if (baseDirectory.isDirectory()) {
                for (int i = 0; i < 1000; i++) {
                    if (i != 0) {
                        abc = baseDirectory.getParentFile().getAbsolutePath();
                    }
                    File file = new File(abc);
                    if (file.list().length == 0) {
                        baseDirectory = new File(abc);
                        if (file.delete()) {
                            System.out.println(i);
                        }
                        i--;
                    } else if (file.isDirectory()) {
                        abc = baseDirectory.getAbsolutePath() + "\\" + onlyDirectory;
                        baseDirectory = new File(abc);
                    }
                }

            }
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }
}

Voila You are done. The directories your file explorer(e.g. windows explorer) could not delete are deleted.

Enjoy your deletion.

January 26, 2011 · Java · No Comments Yet

Folder Depth in NTFS System

One curiosity of creating directory under directory and yet another directory under that led me to write a program in java as:

import java.io.File;
public class ThousandDirectory {
    public static void main(String[] args) {
        String abc = "D:\\ThousandDirectory";
        String onlyDirectory = "ThousandDirectory";
        File baseDirectory = new File(abc);
        if (baseDirectory.mkdir()) {
            for (int i = 0; i < 1000; i++) {
                abc = baseDirectory.getAbsolutePath() + "\\" + onlyDirectory;
                File file = new File(abc);
                if (file.mkdir()) {
                    baseDirectory = new File(abc);
                    //System.out.println(abc);
                }
            }
        }
    }
}

What I found was program was hanged! It didn’t recover. And it looked strange to me that the reason was because OS didn’t support the folder depth level above 255 characters.
There is no official published NTFS file specification...however, under NTFS the directory depth is limited by the 255 character file name limit; directory depth cannot be more that.
Want to know more on other file system will update the same post later.

January 19, 2011 · Java · Comments (1)

Annotations and Reflections

Annotations and reflections are the enhancement in Java for fewer configurations and more convention. We can say it as “Convention over Configuration”. Custom annotations are very powerful concept in Java. Different frameworks available in market use annotations in greater frequency. With Java EE 6 we can even create a web project without web.xml all because of annotations and reflections. Also a JSF2 project can be without faces-config.xml. So the curiosity of learning annotations and how it is being developed led me to a very good article by Jeff Warren.

What I found in learning annotations are they alone are not useful unless we use reflections. The purpose of custom annotations development for our own project or to enhance annotations of the existing frameworks reflections are the key.

By Definition:

An annotation, in the Java computer programming language, is a special form of syntactic metadata that can be added to Java source code. Classes, methods, variables, parameters and packages may be annotated. Unlike Javadoc tags, Java annotations can be reflective in that they can be embedded in class files generated by the compiler and may be retained by the Java VM to be made retrievable at run-time.

Annotations aren’t executed like code, but, rather, mark code in such a way that code processors may alter their behavior based on the metadata information
Hence what happens in writing custom annotations or how different frameworks and even JavaEE is using annotations can be as follows:
• Write custom annotations
• Read the classpath on runtime
• Find out the annotations used.
• And perform the appropriate actions based on the annotations.

But IMHO with the excess use of annotations debugging for the developer might be a lot difficult.

January 18, 2011 · Java · No Comments Yet
Next Page »