Hey, I've just started messing around with reading from text documents and I've done fairly well in my experiments so-far; I just ran into a small problem with the one part of the code that I was sure would work. When running the program everything runs perfectly except for my if statements. Every single character, which is either a 1 or a 0, is always printing ""+charText+" is null." when I run the program. I haven't done much with strings/char variables before so I'm probably making some simple mistake, if anyone can enlighten me please do so.
MapReaderTest.java
import java.io.*; class MapReaderTest { public static void main (String args[]) throws IOException { String lineText; char charText; int lineCounter =0; int characterCounter = 0; BufferedReader inputStream = new BufferedReader(new FileReader("Map.txt")); while( (lineText = inputStream.readLine()) != null) //While the current line doesn't have nothingon it then keep looping { lineCounter++; System.out.println(""+lineText+" is the current line."); for(int i = 0; i < lineText.length(); i++) //Loops through each character in the string until the string ends. { charText = lineText.charAt(i); if(charText == 0) { System.out.println(""+charText+" is a zero."); } else if(charText == 1) { System.out.println(""+charText+" is a one."); } else { System.out.println(""+charText+" is null."); } } } inputStream.close(); } }
Map.txt
0110101101 1001010010 0001110001 1110001100