Results 1 to 2 of 2
  1. #1
    ethann_91 is offline Member
    Join Date
    Jan 2010
    Posts
    2
    Rep Power
    0

    Default Error on reading text from a file.

    Hi,
    I am new to java and right now stuck in a simple issue i believe,
    i am trying to make a applt. that lets the user save information on to a file and
    then read the information saved. My problem is that if the user saved information on to the file and then reads the information once everything goes perfectly and the information is displayed exactly as he saved it, but if the user runes the WHILE statement again and reads the same exact information again i get a error.

    Here is the code:

    1. Saving Text on to file:
    Java Code:
    if (respuestaPrimera.equalsIgnoreCase("E")) {
              String respuesta = "s";    
              while (respuesta.equalsIgnoreCase("s") ) {
            	  
            	 cuentaExtracciones++;  	  
                        		
    			 String cantidadExtraccion1;
                 
    			 String razon;
    
    			 String fecha;
    			 
    			 System.out.print("Cantidad de Extraccion o Gasto?: ");
    
    			 cantidadExtraccion1 = escaner1.next();
    			 Double extraccionDouble = Double.valueOf(cantidadExtraccion1).doubleValue();
    			 System.out.print("Razon de Extraccion: ");
    
    			 razon = escaner1.next();
    
    			 System.out.print("Fecha de Extraccion: ");
    
    			 fecha = escaner1.next();
                 
    			 saldo.deduce(util.leersActual(), extraccionDouble);
    			 
    			 flujoObjetoSalidac.writeObject(cantidadExtraccion1);                     
    			 flujoObjetoSalidaf.writeObject(fecha);
    			 flujoObjetoSalidar.writeObject(razon);
    			 
    			 
    			 System.out.print("Quisiera Realizar Otra Extraccion (S - N): ");
    			 respuesta = escaner1.next();
    			 
              }
    2.Reading Text From File:
    Java Code:
    if (respuestaPrimera.equalsIgnoreCase("x")) {
            	  
            	  for (int i = 0; i < cuentaExtracciones; i++ ){
            		  String razon1;
            		  String fecha1;
            		  String cantidad1;
            		  
           		  
            		  try {
            		  fecha1 = flujoObjetoEntradaF.readObject().toString();
            		  razon1 = flujoObjetoEntradaR.readObject().toString();
            		  cantidad1 = flujoObjetoEntradaC.readObject().toString();
            		  
            		  System.out.println("");
            		  System.out.print(" Fecha: " + fecha1);
            		  System.out.print(" Cantidad: " + cantidad1);
            		  System.out.print(" Razon: " + razon1);
            		  flujoObjetoEntradaC.close();flujoObjetoEntradaF.close();
                              flujoObjetoEntradaR.close();
            		  }
            		  catch (ClassNotFoundException e) {
            			  System.out.println("Error");
            		  }
            		  
            	  }
    The Error:
    Exception in thread "main" java.io.IOException: Not a valide controler.
    at java.io.FileInputStream.read(Native Method)
    at Java.io.ObjectInputStream$PeekInputStream.peek(Obj ectInputStream.java:2249)
    at java.io.ObjectInputStream$BlockDataInputStream.pee k(ObjectInputStream.java:2542)
    at java.io.ObjectInputStream$BlockDataInputStream.pee kByte(ObjectInputStream.java:2552)
    at java.io.ObjectInputStream.readObject0(ObjectInputS tream.java:1297)
    at java.io.ObjectInputStream.readObject(ObjectInputSt ream.java:351)
    at com.eitan.dispaly.Display.main(Display.java:146)
    [/SIZE]

    Any ideas how can i read the file more then once without getting this error?

    PD: I do .close() bought the read and write object after every run thorough them.
    And obviously this error only appears if i am trying to read the file again.
    Last edited by ethann_91; 01-19-2010 at 04:18 PM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    So how many times and in how many fora are you going to place this same darn question? Please do not cross-post without notifying others that you are doing so as it will only bring you flames. For details on why, please look here: BeForthrightWhenCrossPostingToOtherSites

Similar Threads

  1. Reading Integers from a text file
    By tress in forum New To Java
    Replies: 6
    Last Post: 02-26-2011, 06:45 PM
  2. Reading a text file
    By diegosened in forum New To Java
    Replies: 4
    Last Post: 01-16-2010, 12:32 AM
  3. Reading Text File with Certain Conditions
    By balaji csc in forum New To Java
    Replies: 1
    Last Post: 11-10-2009, 12:38 PM
  4. Reading two text file and sum them up
    By matt_well in forum New To Java
    Replies: 36
    Last Post: 07-22-2008, 03:55 AM
  5. Reading text file
    By Lennon-Guru in forum New To Java
    Replies: 1
    Last Post: 12-16-2007, 12:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •