Porque o código não funciona?

1 resposta
0

Bom dia Pessoal!

Alguém pode me dizer porque não esta mostrando o texo do arquivo?

public static void main(String[] args) throws IOException 
	{	
		Scanner s = new Scanner(System.in);
		PrintStream p = new PrintStream("arquivo.txt");
		while (s.hasNextLine())
		{
			p.println(s.nextLine());
		}
	
	}

1 Resposta

W

O contrutor do PrintStream ta errado:

PrintStream(OutputStream out)
PrintStream(OutputStream out, boolean autoFlush)

Voce poderia fazer algo do tipo:

PrintStream st = new PrintStream(new FileOutputStream("arquivo.txt"));

Dica:

Na linha public static void main(String[] args) throws IOException tira o throws IOException e trata essa exception. Muito mais facil pra detectar erros.

//Daniel

Criado 27 de outubro de 2008
Ultima resposta 27 de out. de 2008
Respostas 1
Participantes 2