// inmediatamente, muestra todo el contenido del archivo
import java.io.*;
import java.util.*;
public class ARCHIVOS
{
PrintStream PS = System.out;
InputStream IS = System.in;
PrintStream A_E = new PrintStream(new FileOutputStream("ENTEROS.TXT"));
PrintStream A_F = new PrintStream(new FileOutputStream("FLOTANTES.TXT"));
PrintStream A_C = new PrintStream(new FileOutputStream("CADENAS.TXT"));
public ARCHIVOS() throws IOException { Ciclo(); }
public static void main(String A[]) throws IOException { new ARCHIVOS(); }
void GrabarDatos(PrintStream ARCHIVO, String DATO) throws IOException
{ ARCHIVO.println(DATO); }
void LeerDatos(String archivo)
{
String Linea;
PS.println("Contenido del archivo -" + archivo + "-:");
try
{
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();
}
void Ciclo() throws IOException
{
StringTokenizer ST = null;
String COMANDO = "", TIPO = "";
while(!COMANDO.equalsIgnoreCase("Salir"))
{
COMANDO = LeeDato("Instrucciòn: ");
ST = new StringTokenizer(COMANDO);
TIPO = ST.nextToken();
if (TIPO.equalsIgnoreCase("G")) GUARDA(ST);
if (TIPO.equalsIgnoreCase("L")) LEE(ST);
}
A_E.close(); A_F.close(); A_C.close();
}
void GUARDA(StringTokenizer ST) throws IOException
{
String TIPO = "";
if (ST.countTokens() != 2) PS.println("Error de cantidad de paràmetros...");
else
{
TIPO = ST.nextToken();
if (TIPO.equalsIgnoreCase("ENTEROS")) GrabarDatos(A_E, ST.nextToken());
if (TIPO.equalsIgnoreCase("FLOTANTES")) GrabarDatos(A_F, ST.nextToken());
if (TIPO.equalsIgnoreCase("CADENAS")) GrabarDatos(A_C, ST.nextToken());
}
}
void LEE(StringTokenizer ST)
{
String TIPO = "";
if (ST.countTokens() != 1) PS.println("Error de cantidad de paràmetros...");
else
{
TIPO = ST.nextToken();
if (TIPO.equalsIgnoreCase("ENTEROS")) LeerDatos("ENTEROS.TXT");
if (TIPO.equalsIgnoreCase("FLOTANTES")) LeerDatos("FLOTANTES.TXT");
if (TIPO.equalsIgnoreCase("CADENAS")) LeerDatos("CADENAS.TXT");
}
}
}