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.
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]
}());}
}
}
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.
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.
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()
}
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.