Вот как бы я это сделал:
import java.io.*;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
try {
PrintWriter requests = new PrintWriter("requests.txt");
PrintWriter responses = new PrintWriter("responses.txt");
PrintWriter currentLog = null;
Scanner s = new Scanner(new File("log.txt"));
while (s.hasNextLine()) {
String line = s.nextLine();
if (line.startsWith("Request from"))
currentLog = requests;
else if (line.startsWith("Response from"))
currentLog = responses;
else if (currentLog != null)
currentLog.println(line);
}
requests.close();
responses.close();
s.close();
} catch (IOException ioex) {
// handle exception...
}
}
}
Учитывая log.txt
Request from Centercord.
2010-12-14 12:42:13.724 [ 6796] ****************************
2010-12-14 12:42:13.724 [ 6796] 1111111111111111
2010-12-14 12:42:13.724 [ 6796]22222222222
Response from Centercord.
2010-12-14 12:42:21.802 [ 5960] 11111111111111
2010-12-14 12:42:21.802 [ 5960] ffffffffffffffffffffffffffff
2010-12-14 12:42:21.802 [ 5960] tttttttttttttttttttttttttttt
Request from Centercord.
2010-12-14 12:42:13.724 [ 6796] ****************************
выдаёт, запросы. Текст
2010-12-14 12:42:13.724 [ 6796] ****************************
2010-12-14 12:42:13.724 [ 6796] 1111111111111111
2010-12-14 12:42:13.724 [ 6796]22222222222
2010-12-14 12:42:13.724 [ 6796] ****************************
... и response.txt
2010-12-14 12:42:21.802 [ 5960] 11111111111111
2010-12-14 12:42:21.802 [ 5960] ffffffffffffffffffffffffffff
2010-12-14 12:42:21.802 [ 5960] tttttttttttttttttttttttttttt