Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getting files from a directory and byte read

Status
Not open for further replies.

akiba201

Programmer
Nov 7, 2005
30
CA
hi there,
i am developing a file integrity checker, i wanna first list files from a given directory and then byte-read each and finally calculate a CRC for ech file. does any one know how to get files from a directory and then byte-red it?

iam using JAVA to write this code.

any help will be much appreciated.
 
To list the files, you need to create a java.io.File object pointing at your directory, then use the listFiles method to get an array of File objects representing the files within it.

Then you can use a java.io.FileInputStream to access the byte data within the files. You can easily create a FileInputStream using a File object from the array above in the constructor.

More efficient file access can be achieved by wrapping the FileInputStream in a BufferedInputStream.

Tim
---------------------------
"Your morbid fear of losing,
destroys the lives you're using." - Ozzy
 
BTW, in future can you post pure Java questions like this one in the Java forum269. This forum is for J2EE questions.

Tim
---------------------------
"Your morbid fear of losing,
destroys the lives you're using." - Ozzy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top