read group of files
hi. i've got an issue. my code is prepared for one file reading:
FileReader fr = new FileReader(file_name);
BufferedReader br = new BufferedReader(fr);
FileWriter fw = new FileWriter("out.txt");
now i have to read a hole directory in a loop for example and write it to one out.txt. how can i do it, what should i put into:
FileReader(?)?. thanks for any advice, best regards!
> now i have to read a hole directory in a loop for
> example and write it to one out.txt. how can i do it,
FireWriters have an append flag for their c'tors, if that's what you want to know. For more information, consider reading the API docs. if you don't know how to use a loop, Google for "Java tutorial".
> what should i put into:
>
> FileReader(?)?. thanks for any advice, best regards!
A reference to a File instance. Best, one obtained from theDirFile.listFiles().
Use file.list(0 to get an array of the files in the folder. Then loop through the array to get the specific files which you can perform the reading, saving each read file contents in a temporary string. Each time a new file is read, append the contents of that file to the temporary string, finally taking the string and saving it into the one single big file that you want.
Jamwaa at 2007-7-12 19:00:23 >

> Each time a new file is read, append the contents of> that file to the temporary string, finally taking the> string and saving it into the one single big file> that you want.No technical need to store the files...