Q:

Reading text files - returning null at the beginning of every line?

Thank you for taking the time to read this. I am creating a program that prints out daily quotes to the user. The overall program is working fine, but when I print out the quotes to the user they read like so:
nullThe truth resists simplicity. There are no spaces before these quotes in the text document. I have a feeling this has to do with initializing a variable, but I am unsure which one, or how exactly it would be best to initialize it. Thank you for your time.
static String[] output = new String[12];
    static String file = "";
    static int counter = 0;

    public static void main(String[] args) throws IOException {
        BufferedReader fileRead = new BufferedReader(new FileReader("C:\\Users\\Owner\\Documents\\quotes.txt"));
        String fileLine = "";
        for (int i = 0; i < 12; i++) {
            fileLine = fileRead.readLine();
            if (fileLine == null) {
                break;
            }
            output[i] += fileLine;
            output[i] += "\n";
        }
        JOptionPane.showMessageDialog(null, output[counter]);
        counter++;
        fileRead.close();
        int ans = JOptionPane.showConfirmDialog(null, "Want to see another quote?", "Daily Quote", JOptionPane.YES_NO_OPTION);
        if (ans == JOptionPane.YES_OPTION) {
            do {
                JOptionPane.showMessageDialog(null, output[counter]);
                counter++;
                ans = JOptionPane.showConfirmDialog(null, "Want to see another quote?", "Daily Quote", JOptionPane.YES_NO_OPTION);
            } while (ans == JOptionPane.YES_OPTION);
            JOptionPane.showMessageDialog(null, "Thanks for using the Daily Quotation machine! Have a nice day!",
                    "Daily Quote", JOptionPane.INFORMATION_MESSAGE);
        }

    }

}

A:

With
static String[] output = new String[12];

the elements of the output array are originally all null. When you later say
output[i] += fileLine;

this results in fileLine being appended to null, which results in the transformation of the null reference to a string "null" and then the concatenation with fileLine. You can see this at work in the minimal example
class Foo {
  public static void main(String args[]) {
    String s = null;
    s += "foo";
    System.out.println(s);  // prints "nullfoo"
  }
}

A fix is to use
output[i] = fileLine;  // = instead of +=

