Upload txt

Boa noite

eu tenho o seguinte codigo que faz upload de arquivo txt:

        UploadedFile arquivo = event.getFile();
        InputStream in = new BufferedInputStream(arquivo.getInputstream());
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        byte[] buf = new byte[1024];
        
        try{
            for (int readNum; (readNum = in.read(buf)) != -1;) {
                bos.write(buf, 0, readNum);
                System.out.println("linha: " + bos.toString());
            }
        } catch (IOException ex) {
            ex.getMessage();
        }

no codigo: bos.write(buf, 0, readNum); ele me retorna o conteudo do arquivo txt eu queria ler linha por linha separando os campos e importando em banco de dados teria alguma forma? utilizando o fileUpload do primefaces?

Obs: Utilizando o seguinte codigo abaixo eu consigo fazer mas não consigo unir os dois codigos para chegar ao resultado que eu quero

        arq = new File(caminho);
        String linha = null;
        
        try{
            FileReader reader = new FileReader(arq);
            BufferedReader leitor = new BufferedReader(reader);
            
            while ((linha = leitor.readLine()) != null){
                StringTokenizer st = new StringTokenizer(linha, "|");
                String matricula = st.nextToken();
                String nome = st.nextToken();
                String data = st.nextToken();
                String valor = st.nextToken();
                String competencia = st.nextToken();
                String processamento = st.nextToken();
                
                System.out.println("Linha: " + linha);
                System.out.println("Coluna1: " + matricula);
                System.out.println("Coluna2: " + nome);
                System.out.println("Coluna3: " + data);
                System.out.println("Coluna4: " + valor);
                System.out.println("Coluna5: " + competencia);
                System.out.println("Coluna6: " + processamento);
            }
            
            leitor.close();
            reader.close();
            
        }catch(Exception e){
            e.getMessage();
        }

grato

Se você tem o InputStream, você consegue instanciar o BufferedReader.InputStream in = new BufferedInputStream(arquivo.getInputstream()); InputStreamReader isr = new InputStreamReader(in); BufferedReader br = new BufferedReader(isr);Mas busque não usar a classe StringTokenizer, ela é uma classe mantida somente para não quebrar compatibildade, se você consultar o javadoc, verá que eles aconselham não usá-la mais.[quote]StringTokenizer is a legacy class that is retained for compatibility reasons although its use is discouraged in new code. It is recommended that anyone seeking this functionality use the split method of String or the java.util.regex package instead.[/quote]