1 Reply Latest reply on Nov 26, 2006 11:18 AM by 807607

    Reader returns String "null"

      I buried this in another recent thread I started in which my OP contained a typed-in synopsis both containing an error and not exhibiting the problem behavior, for which I apologize. Here is syntactically correct working code via copy-paste:
      import java.io.*;
      public class Test {
        final static BufferedReader
          stdin = new BufferedReader(new InputStreamReader(System.in));
        private static String getText() {
          String s = "--";  //suffix indicates continuation on next input line
          try {
              s = s.substring(0, s.length() - 2) + stdin.readLine();
            while (s.endsWith("--"));
          } catch (IOException e) {
          return s;
        public static void main(String[] args) {
          String s;
          do {
            System.out.print("Enter text: ");
            s = getText();
            if (s.equals("null")) {
              System.out.println("\"null\" seen.");
              s = null;  }
          } while (s != null);
      Upon entry of Ctrl-Z, the output is: "null" seen.
      The string "null" is not entered by the user.
      I must implicitly be causing a stringOf(null) someplace but I don't see where.