user2814520
user2814520

Reputation: 73

Using the same BufferedReader object to read more than one files

I am writing some code to parse all the files present in the current folder and subfolders. It is able to read all the files but I am getting data only from the last file it reads, while I need data from all the files. Any help on this will be much appreciated. Below is the code format I am using:

public static void scanLogs (String loc)throws IOException{
BufferedReader br= new BufferedReader (new FileReader (loc));
String line=br.readLine();
while(line!=null){
//process the input file
FileWriter fw = new FileWriter(WriteFileLoc.csv);
PrintWriter pw = new PrintWriter(fw);
pw.print();
line=br.readLine(); 
}
pw.flush();
pw.close();
fw.close();
br.close();
}

Upvotes: 0

Views: 326

Answers (1)

Tom
Tom

Reputation: 44881

You need to open the file for appending:

FileWriter fw = new FileWriter(WriteFileLoc.csv, true);

See: http://docs.oracle.com/javase/7/docs/api/java/io/FileWriter.html#FileWriter%28java.io.File%29

Upvotes: 3

Related Questions