本文介绍了在java中如何获取给定目录中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个Java代码,在给定目录名称的情况下,我应该能够获取所有以list开头的文件(例如list *),并逐行(逐行)读取每个文件,然后执行一些操作处理中.

I want to write a java code, where given a directory name, I should be able to get all the files starting with list (so something like list*) and read each file one by one (linewise), and do some processing .

哪些类是可用的,并建议您阅读目录.我的选择是按File.list读取所有文件名,然后选择以list开头的文件名.

What classes are available and recommended to read a directory. Is my option is to read all file names by File.list and then pick the ones which start with list..

谢谢

推荐答案

嗯,最核心的类是 File .

此外, File 的方法还需要一些类(例如 FileFilter 等)

Besides that there are some classes that File's methods need (like FileFilter etc.)

您还可以尝试看看实用程序库,例如 Apache Commons IO .

You can also try and have a look at utility libraries like Apache Commons IO.

这篇关于在java中如何获取给定目录中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 19:17