
-----------------------------------
username123
Thu Nov 12, 2015 9:15 am

output.println doesn't seem to save data to file
-----------------------------------
What the title says. When I try to display the contents of itemList.txt, nothing shows up.

PrintWriter output = new PrintWriter(itemList);
    double price = 0;
    String itemNumber;
    
    System.out.println("\nChoose a section between the following: monitors, motherboards, CPUs, keyboards, HD/SSDs, mice, and cases. Press N to stop browsing.");
    answer = input.next();
    
    while(!answer.equals("N")||!answer.equals("n"))
    {    
      if(answer.equals("Monitors")||answer.equals("monitors"))
      {
        //Displays the list of monitors
        for(int i = 0; i < 3; i++)
        {
          System.out.println(lines

-----------------------------------
Zren
Thu Nov 12, 2015 9:28 am

RE:output.println doesn\'t seem to save data to file
-----------------------------------
write()/println() don't actually write to the file, they just keep it in memory until you've flushed the stream which will write all that's in memory to the file. You also need to close the file once you're done i/o operations on it.

Closing the stream automatically flushes the stream.

http://docs.oracle.com/javase/7/docs/api/java/io/PrintStream.html#close()
