Solucionado (ver solução)
Solucionado
(ver solução)
2
respostas

Dúvida no Ex. 8 da Aula 4 - Pacote java.io

Boa Tarde Nao conseguir executar o arquivo "saida.txt".

A diigitar no console e dpois de ter dado um F5 no projeto e abrir o arquivo saida.txt o eclipse gera um erro dizendo:

Editor could not be initialized java heap space

Segue o código

package br.com.phdeveloper.programa;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.util.Scanner;

public class TesteIO {

    public static void main(String[] args) throws IOException {

        Scanner entrada = new Scanner(System.in);//new Scanner(new FileInputStream("arquivo.txt"));
        PrintStream saida = new PrintStream("saida.txt");

        while (entrada.hasNextLine()) {
            saida.println(entrada.hasNextLine());
        }

        saida.close();
        entrada.close();
    }
}
2 respostas

Você está criando um loop infinito, por isso o java heap space

public class TesteIO {

    public static void main(String[] args) throws IOException {

        Scanner entrada = new Scanner(System.in);//new Scanner(new FileInputStream("arquivo.txt"));
        PrintStream saida = new PrintStream("saida.txt");

        while (entrada.hasNextLine()) {
            saida.println(entrada.nextLine());//<---Arruma esta linha
        }

        saida.close();
        entrada.close();
    }
}
`
solução!

Obrigado.