The if statement in my java programing may have an error

  Kiến thức lập trình

I am trying to delete from a file. If the user puts done, the data that was just input into the file gets deleted

public void getDate(){

    try{
      

     

      long count= Files.lines(Paths.get("savedata.txt")).count();
      Scanner scanner= new Scanner(System.in);
  
      Scanner readlines = new Scanner("savedata.txt");
    FileWriter savedata = new FileWriter("savedata.txt", true);
    PrintWriter writer = new PrintWriter(savedata);
    Homework homework1= new Homework("empty", LocalDate.now());

    System.out.println("Enter the due date of the homework: YYYY-MM-DD");
    homework1.dueDate= LocalDate.parse(scanner.nextLine());
      
      
        
    if(scanner.equals("done")){
      readlines.useDelimiter(Pattern.compile("//"));
      System.out.println(readlines.delimiter());
     return;
     }
       writer.println(homework1.dueDate);
       writer.close();
       

       
       
  }catch(Exception c){

  }

  
}

I have tried almost every way of deleting from a file but I think it may just be my if statement.

New contributor

Natalie Ajmeri is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

LEAVE A COMMENT