How to get data from two different txt, Java

1
I have two .txt and I want to create a new txt by joining some data from these two .txt files, it follows below how I get the .txt data, can someone give me a path how to do this? I was wondering if you could throw the data into an array.

        scanner = new Scanner(new FileReader("caminho"))
        .useDelimiter(",|\n");


        while (scanner.hasNext()) {
            String nome = scanner.next();
            String rg = scanner.next();
            String cpf = scanner.next();
    
asked by anonymous 17.03.2014 / 22:45

1 answer

1

A nice way is to use FileWriter methods to create / edit the file and FileReader to read.

    public void gravar() {
            FileWriter fileWriter;
            BufferedWriter bufferedWriter;
            try {
                fileWriter = new FileWriter("configuracoes\config.txt");
                bufferedWriter = new BufferedWriter(fileWriter);
                bufferedWriter.write("localhost");
                bufferedWriter.close();
                fileWriter.close();
            } catch (IOException ex) {
                JOptionPane.showMessageDialog(null, "Ocorreu um erro:\n" + ex.getMessage());
            }
        }
public final void lerArquivo() {

        try {
            FileReader fileReader = new FileReader("configuracoes\config.txt");
            BufferedReader br = new BufferedReader(fileReader);
            try {
                setIP(br.readLine());
                br.close();
                setUrlPorIP(getIP());

            } catch (IOException ex) {
                BancoDeDados.database.tratamentoDeErro(ex, "");
            }

        } catch (FileNotFoundException ex) {
            new File("configuracoes").mkdir();
            File f = new File("configuracoes\config.txt");
            try {
                f.createNewFile();
                gravarLinhaDeIP();
                lerArquivoConfig();
            } catch (IOException ex1) {
                //JOptionPane.showMessageDialog(null, "O arquivo 'config.txt' não existe.\n"
                //      + "Foi tentado cria-lo mas algo saiu errado.\n"
                //    + "Tente criar o arquivo Manualmente");
            }

        }

    }

Official Documentation:

link link

    
17.03.2014 / 23:46