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!

[413 byte] By [alcatraz123a] at [2007-11-27 7:08:57]
# 1
you mean you want to concatenate the files in any order?
tom_jansena at 2007-7-12 19:00:23 > top of Java-index,Java Essentials,Java Programming...
# 2

> 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().

CeciNEstPasUnProgrammeura at 2007-7-12 19:00:23 > top of Java-index,Java Essentials,Java Programming...
# 3

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 > top of Java-index,Java Essentials,Java Programming...
# 4
> 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...
CeciNEstPasUnProgrammeura at 2007-7-12 19:00:23 > top of Java-index,Java Essentials,Java Programming...
# 5
> file.list()you mean file.listFiles()Like:File directory = new File("c:/temp");File[] allFiles = directory.listFiles();Then make a loop and have a reader for each file in allFiles.
tom_jansena at 2007-7-12 19:00:23 > top of Java-index,Java Essentials,Java Programming...
# 6
thanks for advice, problem issue solved. REGARDS:)
alcatraz123a at 2007-7-12 19:00:23 > top of Java-index,Java Essentials,Java Programming...