2
I’m taking all the lines of my file. However I can’t get first and last to save in a variable.
I have following code snippet to read file:
ler = new Scanner("C:\\Users\\Douglas Williamn\\Documents\\2244.txt");
    String romaneioTxt = ler.nextLine();
    System.out.printf("\nConteúdo do arquivo texto:\n");
    try {
        BufferedReader lerArquivo = new BufferedReader(
                new InputStreamReader(new FileInputStream(romaneioTxt), "UTF-8"));
        linha = lerArquivo.readLine(); // lê a primeira linha
        while (linha != null) {
            if (linha.split("/n") != null) {
                array = linha.split("@#");
                resultadoCTRC = array[2];
                resultadoVolume = array[5];
                resultadoDestinatario = array[6];
                resultadoPPE = array[7];
                // Quando vou buscar as informações na posição 17  e 19
                // Dar erro por que primeira e segunda linha tem apenas 7 posições
                resultadoCidade = array[17];
                resultadoTelefone = array[19];
                System.out.println("CTRC: " + resultadoCTRC);
                System.out.println("Volume: " + resultadoVolume);
                System.out.println("Destinatario: " + resultadoDestinatario);
                System.out.println("PPE: " + resultadoPPE);
                System.out.println("Cidade: " + resultadoCidade);
                System.out.println("Telefone: " + resultadoTelefone);
                System.out.println("\n");
                linha = lerArquivo.readLine(); // lê da segunda até a última linha
                System.out.println(linha);
            }
        }
        lerArquivo.close();
    } catch (IOException e) {
        System.err.printf("Erro na abertura do arquivo: %s.\n", e.getMessage());
    }  
Worked now?
– Reginaldo Rigo
worked for first line. ultimaline = line; // if the file has a single line. If the file has more than one line ? I forgot to comment on this. This last line is the same as the first, ie with the same texts.
– Douglas William