Results 1 to 6 of 6

Thread: Problem reading a text file

  1. #1
    Join Date
    Dec 2009
    Posts
    192

    Problem reading a text file

    Hello
    How to read a text file that contains blank lines because the method readline () returns me.
    Code:
    java.lang.StringIndexOutOfBoundsException: 
    String index out of range: -1
    while the next line is not empty. I have no clue what is going on in the code, but I think I must have done something wrong in my code. so, please help me. Thanks in advance.

  2. #2
    Join Date
    Dec 2009
    Posts
    296

    Re: Problem reading a text file

    Hello,
    Even I have a similar kind of a problem in my code, I am very new to java and I have tried something , just have a look at it
    Code:
     Public class Flux_1 {
     
    	Public static void hand(Statement stmt, String file, String[] v) {	
    		String v = nom_tbl[2];
    String v = sep_chp[3];
    String v = titre_col[4];
    String v = def_tbl[6];
    String[] nm = v[7].split("[|]");
    Integer nb_chp = 0;
    String s = "";
    String vue = "";
    StringBuffer s0 = new StringBuffer();
    / / System.out.println (v [8]);		
    			
    		   InputStream ips =new FileInputStream(file);
    InputStreamReader PRRO =new InputStreamReader(ips);
    BufferedReader br =new BufferedReader(PRRO);
    String ln;
    			/ / read ln by ln
    			
    				 while(v.length<nb_chp)
    				 	{ln + = br.readLine();
    v = ln.split("["+ + sep_chp"]", 0);}
    				 / / extraction and construction of the insertion rqte
    				 for(int i =0; i <nm.length; i + +)
    				 	{vue = v[Integer.parseInt(nm[i], 10)-1];
    / / System.out.println (nm [i] + "-" + vue);
    				 	 if(worth.equals("")| | vue.equals(" ")){vue = "NULL";}else{vue = "'"+ + vue"' ,";}
    				
    				 try{stmt.execute(s);}catch(Final SQLException e){}
    System.out.System.out.println("Sql"+ s);
    				 }
    			br.close();
    			}
    		catch (Exception e) {System.out.System.out.println("popo"+ e.function toString() {
        [native code]
    }());} 
    	}
    }

  3. #3
    Join Date
    Nov 2009
    Posts
    347

    Re: Problem reading a text file

    Hello,
    Are you sure that your exception is thrown at line, I think this should not through an exception on this line, because
    Code:
    while ((line = br.readLine())!=null)
    The is line in your code exists that is why I doubt that you are getting that error. Still, remove this line from your code and just try running the code and see what error you get then.

  4. #4
    Join Date
    Dec 2009
    Posts
    192

    Re: Problem reading a text file

    Hello,
    On the following line , I am using the while loop
    Here is the part of the code
    Code:
    while(v.length<nb_chp)
    				 	{ln + = br.readLine();
    v = ln.split("["+ + sep_chp"]", 0);}
    and the lines are read from a file, but not perfectly, so if you have any idea or if you have any solution for this then please let me know. Thanks in advance.

  5. #5
    Join Date
    Nov 2009
    Posts
    518

    Re: Problem reading a text file

    Hello,
    You can give us the complete stack of the exception?
    Instead of this
    Code:
    catch (Exception e) {System.out.System.out.println("example"+ e.function toString() {
        [native code]
    }());}
    you can do this
    Code:
    catch (Exception e) {
    System.err.print("example");
    e.printStackTrace();
    System.err.System.out.println()
    }

  6. #6
    Join Date
    Nov 2009
    Posts
    583

    Re: Problem reading a text file

    Hello,
    I think you should use this line in your code and see if it works
    Code:
    if(r.substring(r.length()-1Line.length()).equals(spch))line = line +" ";
    That would have caused the problem. In dissecting the vacuum extraction line is causing the error returned when it should not be the result of the analysis file. By moving the line of code after the while, I think the problem can be solved.

Similar Threads

  1. Reading a text file divided by tab
    By Cooper Sheldon in forum Software Development
    Replies: 4
    Last Post: 08-09-2012, 04:08 PM
  2. Reading text file in VC++ display it in textbox
    By molocas in forum Software Development
    Replies: 1
    Last Post: 26-07-2010, 10:34 AM
  3. Problem in reading file in java
    By TechGate in forum Software Development
    Replies: 5
    Last Post: 02-02-2010, 03:05 AM
  4. Error: problem opening file for reading
    By Digamber in forum Operating Systems
    Replies: 3
    Last Post: 26-08-2009, 07:03 PM
  5. Reading text string from text file (PHP)
    By Moderate in forum Software Development
    Replies: 3
    Last Post: 16-01-2009, 03:27 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,872,941.77609 seconds with 17 queries