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
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.