d� uma olhada no c�digo fonte em anexo que ele me ajudou bastante com uma
d�vida semelhante � sua e resolveu o meu problema.

at�, Herbert.


----- Original Message -----
From: "acarlos ." <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, September 04, 2002 9:58 PM
Subject: [java-list] d�vida em java.io


> pessoal,
>
>        estou com um probleminha: preciso colocar o
> "conte�do" do m�todo getOutputStream() da classe
> Process em um arquivo texto. Procurei na API do pacote
> java.io mas eu fiquei com mais d�vidas do que as que
> eu j� tinha. Algu�m pode me ajudar, dizendo como
> colocar o fluxo do m�todo  Process.getOutputStream()
> dentro de um arquivo texto.
>        Obrigado,
>
> Carlos.
>
> _______________________________________________________________________
> Yahoo! PageBuilder
> O super editor para cria��o de sites: � gr�tis, f�cil e r�pido.
> http://br.geocities.yahoo.com/v/pb.html
>
> ------------------------------ LISTA SOUJAVA ----------------------------
> http://www.soujava.org.br  -  Sociedade de Usu�rios Java da Sucesu-SP
> d�vidas mais comuns: http://www.soujava.org.br/faq.htm
> regras da lista: http://www.soujava.org.br/regras.htm
> historico: http://www.mail-archive.com/java-list%40soujava.org.br
> para sair da lista: envie email para [EMAIL PROTECTED]
> -------------------------------------------------------------------------
>
>
>
/*
Universidade Federal de Ouro Preto
Departamento de Computa��o
Eduardo Magno <[EMAIL PROTECTED]>

Este Aplicativo Java l� um arquivo de nome
"input.txt" e grava um novo arquivo de nome
"output.txt", havendo um tratamento especial
no padr�o dos arquivos de sa�da (outputRule)
da linguagem JPearl.
*/

import java.io.*;
import java.util.*;

public class OutputRule {
    private DataOutputStream output;
    private DataInputStream input;
	private byte value, value2, value3;
	private String variable;
	private boolean loop;
	private Integer integer_time;
	private Calendar time;

	public OutputRule() {
		try {
            input = new DataInputStream( new FileInputStream( "input.txt" ) );
            output = new DataOutputStream( new FileOutputStream( "output.txt" ) );
        }
        catch ( IOException e ) { }

        try {
			while (true) {
            	value = input.readByte();
            	if ( (char)value == '/' ) {
           			value2 = input.readByte();
           			if ( (char)value2 == '*' ) { //trecho comentado
						loop = true;
	            		value = input.readByte();
           				while ( loop ) {
		            		value2 = input.readByte();
		            		if ( (char)value == '*' && (char)value2 == '/' ) { loop = false; }
							else {
								if ( (char)value2 == '*' ) {
									value = input.readByte();
									if ( (char)value == '/' ) { loop = false; }
								}
								else {
									value = input.readByte();
								}
							}
						} //end while
					} // if value2 == '*'
					else { // value == '/' and value2 != '*'
						if ( (char)value2 == '/' ) { //linha comentada
							loop = true;
	            			value = input.readByte();
           					while ( loop ) {
		            			value2 = input.readByte();
		            			if ( value == 13 && value2 == 10 ) { loop = false; }
								else { // 13 10 = quebra de linha
									if ( value2 == 13 ) {
										value = input.readByte();
										if ( value == 10 ) { loop = false; }
									}
									else {
										value = input.readByte();
									}
								}
							} //end while
						} // if value2 == '/'
						else {
							output.writeByte( (char)value );
							output.writeByte( (char)value2 );
						}
					} //else
				}// if
				else { // value != '/'

            		if ( (char)value == '#' ) {
						variable = "";
            			value2 = input.readByte();
            			if ( (char)value2 == '#' ) {
							output.writeByte( (char)value2 );
						}
						else { //variavel de reestrutura��o
           					variable = "" + (char)value2;
            				while ( (char)value2 != ' ') {
            					value2 = input.readByte();
            					variable = variable + (char)value2;
							} // end while
							output.writeBytes( variable );
						}
					}
					else { //value != '/' && value !='#'
						if ( (char)value == 92 ) { // 92 = '\'
            				value2 = input.readByte();
            				if ( (char)value2 == 'n' ) { /* Passa para proxima lina */
								output.writeByte( 13 );
								output.writeByte( 10 ); // 13 10 = quebra de linha
							}
							else { // value == '\' and value2 != 'n'
								variable = "" + (char)value2;
								loop = true;
								int i = 0;
								while  ( loop && i < 4 ) {
									switch ( i ) {
										case 0 :
											if ( variable.equals("d") || variable.equals("t")) {
												value3 = input.readByte();
											} else { loop = false; }
											break;
										case 1 :
											if ( variable.equals("da") || variable.equals("ti")) {
												value3 = input.readByte();
											} else { loop = false; }
											break;
										case 2 :
											if ( variable.equals("dat") || variable.equals("tim")) {
												value3 = input.readByte();
											} else { loop = false; }
											break;
										case 3 :
											if ( variable.equals("date") || variable.equals("time")) {
												time = Calendar.getInstance();
												if ( variable.equals("date") ) {
													integer_time = new Integer(time.get(time.DAY_OF_MONTH));
													output.writeBytes( integer_time.toString() );
													output.writeByte( '/' );
													integer_time = new Integer((time.get(time.MONTH)+1));
													output.writeBytes( integer_time.toString() );
													output.writeByte( '/' );
													integer_time = new Integer(time.get(time.YEAR));
													output.writeBytes( integer_time.toString() );
												}
												else {
													if ( variable.equals("time") ) {
														integer_time = new Integer(time.get(time.HOUR));
														output.writeBytes( integer_time.toString() );
														output.writeByte( ':' );
														integer_time = new Integer(time.get(time.MINUTE));
														output.writeBytes( integer_time.toString() );
														output.writeByte( ':' );
														integer_time = new Integer(time.get(time.SECOND));
														output.writeBytes( integer_time.toString() );
														output.writeByte( ' ' );
														if (time.get(time.AM_PM) == 0) {
															output.writeBytes( "AM" );
														}
														else {output.writeBytes( "PM" );}
													}
												}
											} else { loop = false; }
											break;
									}
									if ( loop ) { variable = variable + (char)value3; }
									i++;
								} //end while
								if ( !loop ) {
									output.writeByte( (char)value );
									output.writeBytes( variable );
								}
							}
						}
						else {
							output.writeByte( (char)value );
						}
					}
				}//else
			} //end while
        } // end try
		catch ( IOException eo ) { }

		try {
			input.close();
			output.close();
	        System.exit( 0 );
		}
	    catch( IOException ex ) { }
	} // OutputRule

	public static void main( String args[] ) {
      new OutputRule();
    }
}

------------------------------ LISTA SOUJAVA ----------------------------
http://www.soujava.org.br  -  Sociedade de Usu�rios Java da Sucesu-SP
d�vidas mais comuns: http://www.soujava.org.br/faq.htm
regras da lista: http://www.soujava.org.br/regras.htm
historico: http://www.mail-archive.com/java-list%40soujava.org.br
para sair da lista: envie email para [EMAIL PROTECTED]
-------------------------------------------------------------------------

Responder a