String Comparison from text file does not return anything -


i beginner in java, trying read text text file , compare strings created within class, reason not output on console , can't wonder why. here's simple code

package binaryserver; import java.io.bufferedreader; import java.io.filenotfoundexception; import java.io.filereader; import java.io.ioexception;   public class driverstate {      public static void main (string[]args) throws filenotfoundexception, ioexception{          string driverstate="";         string not="not drowsy";         string yes="drowsy";           try(bufferedreader br = new bufferedreader(new filereader("c:/users/mohamed ayman/desktop/state.txt"))) {                 stringbuilder sb = new stringbuilder();                 string line = br.readline();                  while (line != null) {                     sb.append(line);                     sb.append(system.lineseparator());                     line = br.readline();                 }                 driverstate = sb.tostring();             }          if (driverstate.equals(not)){              system.out.println("user not drowsy");         }         else if (driverstate.equals(yes)){              system.out.println("user drowsy");         }     } } 

for one, you're adding line breaks driverstate not present in yes or no, both comparisons return false.

on side note: java naming convention variables, fields , methods lower camel case, driverstate instead of driverstate.


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -