从Java读取文件系统结构

编程入门 行业动态 更新时间:2024-10-21 09:12:07
本文介绍了从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读取文件系统结构

本文发布于:2023-05-28 06:55:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/315109.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件系统   结构   Java

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!