PrintWriter object doesn't write lines into out.txt file, however creates it.
reading from BufferedReader object works fine.
package extractcdr;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ExtractCDR {
public static void main(String[] args) throws FileNotFoundException, IOException {
BufferedReader brnew BufferedReader(new FileReader("in.txt"));
PrintWriter pw=ew PrintWriter(new FileWriter("out.txt"));
int t=0;
String line;
String[] lines=new String[t+1];
String interf;
String date;
String duration;
Pattern pattern_date=Pattern.compile("\\w+\\s:\\s\\w+\\s(\\d\\d:\\d\\d:\\d\\d).{13}(\\w{3}\\s\\d+\\s\\d+)");
Pattern pattern_duration=Pattern.compile("\\s\\w{3}\\s(\\d\\d:\\d\\d:\\d\\d)");
Pattern pattern_interf=Pattern.compile("\\s\\w+\\s(\\d\\/\\d\\/*\\d*:\\d\\d)");
Matcher matcher;
while((line=br.readLine())!=null)
{
lines[t]=line;
lines=Arrays.copyOf(lines, lines.length+1);
if(lines[t].contains("Telephony"))
{
matcher=pattern_date.matcher(lines[t-2]);
if(matcher.find())
{
date=matcher.group(1)+" "+matcher.group(2);
System.out.println(date);
pw.println(date);
}
matcher=pattern_duration.matcher(lines[t-1]);
if(matcher.find())
{
duration=matcher.group(1);
System.out.println(duration);
pw.println(duration);
}
matcher=pattern_interf.matcher(lines[t]);
if(matcher.find())
{
interf=matcher.group(1);
System.out.println(interf);
System.out.println();
pw.println(interf);
pw.println("\n");
}
}
t++;
}
}
}
On standard output I can see with out.printline that content is correctly grabbed and processed but nothing is the out.txt file.