开发者

array of text files

is it possible to create an array of text files ?

lets say i have a folder which contains a set of 20 text files.

I would like to store开发者_如何学Go the text file inside the array to do some processing and iterate thru all the files.


Sure. Try Apache Commons IO.

Iterator it = FileUtils.iterateFiles(dir, new String[]{"txt"},false);
while(it.hasNext()){
    File txtFile = it.next();
}

There is also a similar method that will return Collection<File> instead of an iterator.


File folder = new File(path);
File[] listOfFiles = folder.listFiles(); 

You can use FileFilter to just get *.txt from all files.


You can store an array of the file names or an array of the InputStream references to the files. But you can't store the text files per se. You could also store the contents of the text files as strings.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜