Friday 11 November 2016

Java Tutorial : Java IO (Java File - How to get a list of file and dir)


Click here to watch in Youtube :
https://www.youtube.com/watch?v=eOuRKIHjXz8&list=UUhwKlOVR041tngjerWxVccw

Work Folder:
Java Tutorial : Java IO (Java File - How to get a list of file and dir) 
FileDemo1.java
import java.io.File;

/*
 *  Read List of Files in a Directory
 */
public class FileDemo1
{

    public static void main(String[] args)
    {
        File file = new File("D:/work/");
        /*
         * Returns an array of strings naming the files and
         * directories in the directory denoted by this
         * abstract pathname.
         */
        String[] strArray = file.list();

        for (String fileName : strArray)
        {
            System.out.println(fileName);
        }
    }

}
Output
HelloWorld.txt
java.txt
misc
myfile.txt
FileDemo2.java
import java.io.File;

/*
 *  Read List of Files in a Directory
 */
public class FileDemo2
{

    public static void main(String[] args)
    {
        File file = new File("D:/work/");
        /*
         * Returns an array of abstract pathnames denoting
         * the files in the directory denoted by this
         * abstract pathname.
         */
        File[] fileArray = file.listFiles();

        for (File file2 : fileArray)
        {
            System.out.println(file2.getName());
        }
    }

}
Output
HelloWorld.txt
java.txt
misc
myfile.txt
Click the below link to download the code:
https://sites.google.com/site/ramj2eev1/home/javabasics/JavaIODemo_File_listfiles_App.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/JavaIODemo_File_listfiles_App

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/882ffbbbc9c8fbb765fb4869059bc3ee253ad31b/BasicJava/JavaIODemo_File_listfiles_App/?at=master

See also:

  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • No comments:

    Post a Comment