Refresh Your Java - Before Java Interview
We are Agile, believe in less Documentation - Only Quick notes (Java Interview Questions) of Java/J2ee Read more....
This example illustates how to seach for a
given file in given directory.
import
java.io.*;
import java.util.ArrayList;
public class SearchFileSystem{
//Search
all file roots (c:, d:, etc.)
//Modified to
return List of files
ArrayList files = new ArrayList();
public ArrayList
searchFile(String name) throws Exception {
File[] roots = File.listRoots();
if(roots != null) {
for
(int i = 0 ; i < roots.length ; i++)
{
ArrayList aux
= recursiveSearch(roots[i], name);
if (aux != null && aux.contains(name))
{
files.add(roots[i].getCanonicalPath());
}
}
}
return
files;
}
//Search from specified root
//Modified to
return List of files
public ArrayList
recursiveSearch(File f, String name) throws Exception
{
if(f.exists()) {
File[] childs = f.listFiles();
if(childs != null) {
for (int i = 0 ;i <
childs.length ; i++) {
if
(childs[i].isDirectory()) {
ArrayList aux = recursiveSearch(childs[i],
name);
if
(aux != null && aux.contains(name))
{
files.add(childs[i].getCanonicalPath());
}
} else if
(name.compareTo(childs[i].getName()) == 0)
{
files.add(childs[i].getCanonicalPath());
}
}
}
}
return
files;
}
}
This Portal is intended to put all Java/J2ee related topics at one single place for quick referance, not only Technical , but also the Project Management Related thing such as Development Process methodoogies build process, unit testing etc.,
This Portal has More than 500 Java Interview Questions (also could be Considered as Quick Notes) very neatly separated topic by topic with simple diagrams which makes you easily understandable. Importantly these are from our Realtime expericance.