title: Using BufferedWriter to get input from the user and write it to a file
body: <p>I just started using Java, so sorry if I ask some very simple questions. I basically have to get the user to continuously integers, and once they enter a negative number, the loop will exit. The code I have written so far does not seem to be able to write the input I get from the user to the file I created, morescores. When I try opening the file or calling it from the main method, it's blank. I've tried searching it up on google, youtube, and on stackoverflow but nothing seems to be working. I"ll appreciate any help I can get :)</p>
  
  <pre><code>package bufferedreader;
  import java.io.*;
  import java.util.Scanner;
  
  
  public class BufferedReader {
  
  /**
   * @param args the command line arguments
   * @throws java.io.IOException
   */
  public static void main(String[] args) throws IOException {
     writeToFile("morescores");
     processFile("morescores");      
  }
  
  
  public static void writeToFile (String filename) throws IOException {
      BufferedWriter outputWriter = new BufferedWriter (new FileWriter ("morescores.txt"));
      int score = 1;            
     while (true) {
     Scanner reader = new Scanner(System.in);
          System.out.print ("Enter a number: ");
         score = reader.nextInt();
          if (score &lt; 0) { 
              break;
         } else {
            outputWriter.write(score);
            outputWriter.newLine();           
      }      
      }
     outputWriter.flush();
     outputWriter.close();
  }
  
  public static void processFile2 (String filename) throws IOException {
      java.io.BufferedReader inputReader = new java.io.BufferedReader(new InputStreamReader (new FileInputStream ("morescores.txt")));
      String line;
      while ((line = inputReader.readLine()) != null) {
          System.out.println (line);
      }
      inputReader.close();
  }
  
  }
  </code></pre>
  
  <p>UPDATE: I fixed the problem haha turns out I was trying to print an integer when it could only be a string.  I actually have a followup question, I also need to find the average of all the numbers the user inputs. How would I do that? How can I write a code so that the program knows how many times the user inputs a value I actually have a followup question, I also need to find the average of all the numbers the user inputs. How would I do that? How can I write a code so that the program knows how many times the user inputs a value</p>