---restore content starts---
1. Read all files (not folders) under the folder under the E Drive (xx.txt;yytxt,gg.txt) directory
E:app
App1
app1.1 Xx.txt
app1.2 Yy.txt
App2
APP2 Gg.txt
2. Code
PackageCom.tansun;ImportJava.io.File;Importjava.util.ArrayList;Importjava.util.List; Public classFileReader { PublicList<string> Ergdoic (File file,list<string>resultfilename) {file[] files=File.listfiles (); if(files==NULL){ returnResultfilename; } for(File f:files) {if(!f.isdirectory ()) {//if not a folderResultfilename.add (F.getpath ()); }Else{ergdoic (f,resultfilename);//If the folder is recursive } } returnResultfilename;//returns a collection of file names } //Run Tests Public Static voidMain (string[] args) {File file=NewFile ("E:\\app"); List<String> list=NewArraylist<string>(); System.out.println (NewFileReader (). ergdoic (file, list)); } }
3. The result is a collection of paths to the file
Recursively reads all files under the directory file