Its a very simple program, but a great one to get your hands on to java file handling stuff. Lets just don't waste time, and get to the codes.......
package deep.indeed.filesInFolder; import java.io.File; public class FilesInCurrentFolder { public static void main(String[] args) { File folder = new File("."); //DOT (.) means the current directory File[] listOfFiles = folder.listFiles(); for(int i=0; i < listOfFiles.length;i++) { if(listOfFiles[i].isFile()) { System.out.println(listOfFiles[i].getName());//Returns only the file name System.out.println(listOfFiles[i].getAbsoluteFile());//Returns the absolute path of the file System.out.println(listOfFiles[i].getAbsolutePath());//Same as getAbsoluteFile System.out.println(listOfFiles[i].getParentFile());//Returns the Parent Directory i.e. the current directory } } } }
Comments
Post a Comment