Reputation: 73
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
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