Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Java
  3. Question
Java

If I Receive the message - Printwriter not writing, what should I do?

Asked by Abigail Abraham Oct 12, 2022 1.0K views 1 answer
Share

About this question

 This program is compiling just fine, and the variables and such seem to be passing through. However, when I open the text file there is no data. Can anyone point me in the right direction or nudge my brain into the right process?


package dvd logger;
import java.util.*;
import java.io.*;
public class DVDLogger {
public DVDLogger() throws IOException
{
    String title = null;
    double price = 0;
    storeDVDInfo(title, price);
}
private void storeDVDInfo(String title, double price) throws IOException
{
    File path = new File("C:\users\crazy\desktop\dvd.txt");
    PrintWriter output = new PrintWriter(path);
    output.printf("%1$s %2$.2f", title, price); 
}
public static void main(String[] args) throws IOException{
    DVDLogger dvd;
    String title;
    double price;
    try (Scanner read = new Scanner(System.in)) {
        dvd = new DVDLogger();
        System.out.printf("%nPlease enter the title of the DVD: ");
        title = read.nextLine();
        System.out.printf("%nPlease enter the price of the DVD: ");
        price = read.nextDouble();
    }
    dvd.storeDVDInfo(title, price);
}
}

Your answer

1 Answer

More Java discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Java Blogs

Guides, tips and career advice on Java from JanBask experts.