public class WriteOrderNumberFile {
private static void copyFile(String sourceFileName, String
destinationFileName, String orderNr) {
// orderNr = "LEC##0000000073";
BufferedReader br = null;
PrintWriter pw = null;
try {
br = new BufferedReader(new FileReader(sourceFileName));
pw = new PrintWriter(new FileWriter(destinationFileName));
String token;
String line;
Scanner inFile;
while ((line = br.readLine()) != null) {
inFile = new Scanner(line);
while (inFile.hasNext()) {
token = inFile.next();
if (token.equals(orderNr)) {
System.out.println(token);
pw.println(line);
while ((line = br.readLine()) != null) {
inFile = new Scanner(line);
while (inFile.hasNext()) {
token = inFile.next();
if (token.equals("Run")) {
br.close();
pw.close();
return;
}
}
pw.println(line);
}
}
}
}
br.close();
pw.close();
} catch (Exception e) {
e.printStackTrace();
} }
public static void main(String[] args) {
String sourceFileName = "D:\\Test Folder\\source.txt";
String destinationFileName = "D:\\Test Folder\\destination.txt";
String orderNr = "LEC##0000000064";
copyFile(sourceFileName, destinationFileName, orderNr); }
}