美文网首页
java教程

java教程

作者: c667ec5a71d8 | 来源:发表于2018-11-23 21:57 被阅读0次

    import java.io.File;

    public class DirList {

        public static void main(String args[]) {

            String dirname = "/java";

            File f1 = new File(dirname);

            if (f1.isDirectory()) {

                System.out.println("Directory of " + dirname);

                String s[] = f1.list();

                for (int i = 0; i < s.length; i++) {

                    File f = new File(dirname + "/" + s[i]);

                    if (f.isDirectory()) {

                        System.out.println(s[i] + " is a directory");

                    } else {

                        System.out.println(s[i] + " is a file");

                    }

                }

            } else {

                System.out.println(dirname + " is not a directory");

            }

        }

    }

    以上实例编译运行结果如下:

    Directory of /java

    bin is a directory

    lib is a directory

    demo is a directory

    test.txt is a file

    README is a file

    index.html is a file

    include is a directory

    相关文章

      网友评论

          本文标题:java教程

          本文链接:https://www.haomeiwen.com/subject/stbsqqtx.html