Hello,
I am writing a small java code which read from a text file line by line and parses each read line(hash seperated).
Here is the code snippet:
in =new BufferedReader(new InputStreamReader(new FileInputStream("file.txt")));
while((linedata =in.readLine())!=null)
{
System.out.println("Linedata: "+linedata);
strparse = linedata.split("#");
line = strparse[1];
System.out.println("Line Number:"+strparse[1]);
}
the data in the sample file is:
#64#080517#090002#9999999999#1#9999999999#N#ABC#-1#QQQ#
#63#080517#090002#9999999999#1#99999999999#N#EDF#-1#WWW#
#67#080517#090002#9999999999#1#99999999999#N#FGH#-1#RRR#
The output after running the java code is:
Linedata:#64#080517#090002#9999999999#1#9999999999#N#ABC#-1#QQQ#
Line Number: 64
Linedata:
java.lang.ArrayIndexOutOfBoundsException: 1
Please advice.
Regards.
programmer321
0
Light Poster
Recommended Answers
Jump to PostFrom this output:
Linedata:
java.lang.ArrayIndexOutOfBoundsException: 1I believe that one of the lines is empty. As you can see nothing is printed after the "Linedata:". So probably you are doing split("#") to an empty line. Therefor the table will have size 0 or 1 (I don't know exactly), …
Jump to PostWhy don't you try this instead:
String linedata = in.readLine(); while( linedata!=null ) { // // // linedata = in.readLine(); }
All 5 Replies
javaAddict
900
Nearly a Senior Poster
Team Colleague
Featured Poster
programmer321
0
Light Poster
javaAddict
900
Nearly a Senior Poster
Team Colleague
Featured Poster
programmer321
0
Light Poster
javaAddict
900
Nearly a Senior Poster
Team Colleague
Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.