java - Reading a file and check whether the lines end with semicolon -


i read text file contains following code.

void main() {     int = 5 ;     float b = 6      double c ;      c = + b ;     cout << c ;  } 

i wanted loop through lines of code , check if each line ends semicolon(;).

i wrote following code , ran on netbeans ide.

int linecount = 0;  bufferedreader readfile = new bufferedreader(new filereader("c:\\readfile2.txt"));  while ((currentline = readfile.readline()) != null) {     linecount++;     if (currentline.endswith(";"))     {      }     else     {         jtextarea2.append("error @ line" + " " + linecount);                        }  } 

after running code, output wasn't suppose be. output

 error @ line 1  error @ line 2 error @ line 4  error @ line 5  error @ line 7 error @ line 8 

the line reading has spaces after ;, try this:

if (currentline.trim().endswith(";")) 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -