Salvar texto em TXT

Ola galera, preciso detectar um erro aqui em tempo de execução só que não tenho como debugar.
Alguém sabe alguma forma simples que eu possa setar um sysout em um arquivo txt???
Tem que ser bem simples, pois tenho acesso somente a uma classe do projeto…

Abraços

O BufferedOuputStream resolve seu problema.

Certo fábio, no meu código abaixo… tem como escrever no mesmo arquivo?

public void writeToFile(String filename, String texto) {
		 BufferedOutputStream bufferedOutput = null;
		 File arquivo = new File(filename);
	     try {
	         if (!arquivo.exists()){   
	        	 bufferedOutput = new BufferedOutputStream(new FileOutputStream(filename));
	         }
	         else{
	        	 //usa mesmo arquivo
	         }
	         bufferedOutput.write(texto.getBytes());
	            
	        } catch (FileNotFoundException ex) {
	            ex.printStackTrace();
	        } catch (IOException ex) {
	            ex.printStackTrace();
	        } finally {
	            try {
	                if (bufferedOutput != null) {
	                    bufferedOutput.flush();
	                    bufferedOutput.close();
	                }
	            } catch (IOException ex) {
	                ex.printStackTrace();
	            }
	        }
	 }
	 
	    public static void main(String[] args) {
	        new Teste().writeToFile("myFile.txt","vai");
	    }

Tem sim…

no seu objeto de FileOutputStream, vc passa no construtor append como true, por exemplo:

File file = new File("arquivo.txt"); FileOutputStream fos new FileOutputStream(file, true);

Aí ele fará o que vc quer.

vou teste

[quote=fabiomedeirosf]Tem sim…

no seu objeto de FileOutputStream, vc passa no construtor append como true, por exemplo:

File file = new File("arquivo.txt"); FileOutputStream fos new FileOutputStream(file, true);

Aí ele fará o que vc quer.[/quote]

Tentei dessa forma e não deu

public void writeToFile(String filename, String texto) throws FileNotFoundException {
		 File arquivo = new File(filename);
		 FileOutputStream fos = new FileOutputStream(arquivo, true); 
		 BufferedOutputStream bufferedOutput = null;
		 BufferedOutputStream bufferedOutput2 = null;
	     try {
	    	 
	    	 //se arquivo texto ainda não existir, cria e grava nele
	         if (!arquivo.exists()){   
	        	 bufferedOutput = new BufferedOutputStream(new FileOutputStream(filename));
	        	 bufferedOutput.write(texto.getBytes()); 
	         }
	         //se arquivo ja existe, só grava
	         else{
	        	 bufferedOutput2 = new BufferedOutputStream(fos);
	        	 bufferedOutput2.write(texto.getBytes()); 
	         }
	         
	            
	        } catch (FileNotFoundException ex) {
	            ex.printStackTrace();
	        } catch (IOException ex) {
	            ex.printStackTrace();
	        } finally {
	            try {
	                if (bufferedOutput != null) {
	                    bufferedOutput.flush();
	                    bufferedOutput.close();
	                }
	            } catch (IOException ex) {
	                ex.printStackTrace();
	            }
	        }
	 }
	 
	    public static void main(String[] args) throws FileNotFoundException {
	        new Teste().writeToFile("logs.txt","vaasdasdi");
	    }

Que erro deu? O que houve?