从Java读取文件系统结构 [英] read file system structure from java

查看:72
本文介绍了从Java读取文件系统结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以读取目录中所有文件夹的名称(而不是子文件夹),并将列表保存在ArrayList等中?

Is it possible to read all the names of folders (not sub-folders) inside a directory and save the list in an ArrayList, etc ?

例如-如果目录中包含以下文件夹-CLIENT1,CLIENT2,CLIENT3等. 我希望ArrayList像这样-[CLIENT1,CLIENT2,CLIENT3等].

e.g- if a directory has the following folders inside it- CLIENT1, CLIENT2, CLIENT3, etc. I want the ArrayList to be something like this- [CLIENT1, CLIENT2, CLIENT3, etc].

这些文件夹位于Unix服务器中,因此可以使用Java代码或Shell脚本(bash/tcsh/etc)或它们的组合来完成.

The folders are in an unix server, so either java code or a shell script(bash/tcsh/etc) or their combination would do.

推荐答案

尝试一下:

File dir = new File("directoryName");
File temp;
String[] children = dir.list();
if (children !=null) {
    for (int i=0; i<children.length; i++) {
        temp = new File(children[i]);
        if(temp.isDirectory()) //add children[i] to arrayList
    }
}

这篇关于从Java读取文件系统结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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