建立档案的阵列在一个目录 [英] Building an array of files in a directory

查看:106
本文介绍了建立档案的阵列在一个目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是如何在Java中做了什么?我想在程序中创建文件名的阵列输出,文件将在我的主目录的人。

How is this done in Java? I wish to create an array of fileNames to output in a program, the files will be the ones in my home directory.

到目前为止,我有:

File[] fileList = new File(user.home).listFiles()

这是我所需要的?

然后,打印出这些文件,可我只是做:

And then, to print out those files, can I just do :

int i = 0;
while (fileList.getNext() != null) {
System.out.println(filelist[i]
i++
}

非常感谢。

推荐答案

看起来你是对的。我更清晰地整理了一下code位。

Looks like you are right on. I've put together your code bit more cleanly.

File[] fileList = new File(System.getProperty("user.home")).listFiles();
        for (int i=0;i < fileList.length;i++) {
            System.out.println(fileList[i]);
        }

这篇关于建立档案的阵列在一个目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆