• Post Reply Bookmark Topic Watch Topic
  • New Topic

How do I read all files in a directory  RSS feed

 
Nanna
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to write the code to read all files under the directory word by word. Does anyone know how to do that.
Thanks
 
Kaustubh Patil
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its very easy..
Just read the API of "java.io.File" class.
All you have to do is to create a "File" object by passing the path of that directory. Then you invoke the listFiles() method on that object which returns you an array of File Objects in that directory.
Try it..
kaustubh.
 
Nanna
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have done that, but my question is how to open and read all those files. Do I need a reader object, and open each file and read word by word ?
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, which you agreed to when you registered, described at http://www.javaranch.com/name.jsp . We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please log in with a new name which meets the requirements.
Thanks.
 
Ganesh Ram
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sure you do as you need to create a reader and later close it also.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!