android - Reading all text files in a directory in Java? -


how scan entire folder in java code , read each text file in separate array? i'm trying have set of locationnodes(class created) on map app i'm creating college campus/side project resume.

when code initializes, want app scan text files in "locationtextfiles" folder. each text file has 3 sets of text: line 0 (the name of location), line 1 (hours building open), , line 2-eof (description of location). take these lines stick them in new locationnode object every time , create new locationnode object repeat process until files found have been read.

what's best way go doing this? have class set it's attributes (name, hourstext, , descriptiontext), i'm assuming function create need public method of same locationnode class?

here go,

file folder = new file("/path/to/files"); file[] listoffiles = folder.listfiles();  (int = 0; < listoffiles.length; i++) {   file file = listoffiles[i];   if (file.isfile() && file.getname().endswith(".txt")) { string content = fileutils.readfiletostring(file);     /* somthing content */   }  } 

you can use array instead of content. suggest don't it, if have huge number of files or each file huge. when huge, mean size exceed ram size.


Comments