how to get file names from a directory or package in eclipse ?
hi ,
I am trying to write a small code here where in i want to get file names from a directory..
here is the code i am trying..
import java.io.*;
public class GetFileList
{
public static void main(String args[]){
File file = new File("home/");
File[] files = file.listFiles();
for (int fileInList = 0; fileInList < files.length; fileInList++)
{
System.out.println(files[fileInList].toString());
}
}
}
but it gives me an error saying
Exception in thread "main" java.lang.NullPointerException
at GetFileList.main(GetFileList.java:7)
(1) could anyone tel me, y is it so ? and what am i supposed to add now to get the file names from the directory..
(2) and i also want to know how to work in the same way in eclipse , so as to get file names from a particular package, instead of a directory...
Thanking you in advance