Arch_demo_2.java_



// Lee N l'ineas en una sola pasada e
// inmediatamente, muestra todo el contenido del archivo

import java.io.*;

public class Arch_demo_2
{
	PrintStream PS = System.out;
	InputStream IS = System.in;

	public Arch_demo_2() throws IOException
	{
		GrabarDatos("Archivo_2.txt");
		LeerDatos("Archivo_2.txt");
	}
  
	public static void main(String A[]) throws IOException { new Arch_demo_2(); }
  
	void GrabarDatos(String archivo) throws IOException
	{
		String CADENA = "  ";
		try
		{
			PrintStream ARCHIVO = new PrintStream(new FileOutputStream(archivo));
			while ((CADENA = LeeDato(">> ")).length() > 0)
				ARCHIVO.println(CADENA);
			ARCHIVO.close();
		}
		catch (IOException e)
		{ PS.println("Error de escritura de archivo: "+e); }
	}
	
	void LeerDatos(String archivo)
	{
		String Linea;
		try
		{
			// DataInputStream ARCHIVO = new DataInputStream(new FileInputStream(archivo));
			BufferedReader ARCHIVO   = new BufferedReader(new InputStreamReader(new FileInputStream(archivo)));
			while((Linea = ARCHIVO.readLine()) != null )
				PS.println(Linea);
			ARCHIVO.close();
		}
		catch (IOException e) { PS.println("Error en archivo de lectura"); }
	}
	
	String LeeDato(String Mensaje) throws IOException
	{
		BufferedReader EntradaDeTeclado = new BufferedReader(new InputStreamReader(System.in));
		PS.print(Mensaje + " ");
		PS.flush();
		return EntradaDeTeclado.readLine();
	}
}