Pick string value from txt

Asked

Viewed 72 times

0

I have in a txt that is mirror of a tax printer, I would like to take the COO number corresponding only to Z REDUCTION, in the example below would like to catch only the value 031717.

02/01/2014 11:50:06                   COO:031717

         REDUÇÃO Z       
MOVIMENTO DO DIA: 01/01/2014

02/01/2014 11:50:06                   COO:031718

         LEITURA X       
MOVIMENTO DO DIA: 01/01/2014

In my Code I can take all the COO and put in another file, but I would like to take only the Z Reduction.

Follows excerpt from the code:

BufferedReader br = new BufferedReader(new FileReader("arquivo.txt"));
        String linha;
        while ((linha = br.readLine())!=null) {
            String texto="";
            if (linha.contains("COO:")) {
                texto = linha.substring(linha.length()-6, linha.length());
                FileWriter escrever = new FileWriter(new SimpleDateFormat("dd-MM-yyyy").format(new Date())+".txt", true);
                escrever.append(texto+"\n");
                escrever.close();
            }
        }
  • After C00, the next word is always the associated term (Z REDUCTION, X READING, ...)?

  • Yes, but in a different line

1 answer

0

If always READ or REDUCE, when passing through the COO create an object that has two fields, COO and type. Then you keep the COO and the guy and you keep that object on a list. At the end you will have a list of objects already processed, so just filter these objects the ones that have REDUCAO or READ, as you need.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.