I am getting java.nio.file.NoSuchFileException

Although the file that is getting this error is in my java project file, when I use print stack trace I get the java.nio.file.NoSuchFileException error. Does anyone maybe know why?

In my code I am writing to a file named savedata.txt which is the file getting the java.nio.file.NoSuchFileException error. Otherwise my code is also deleting from this file. In order to delete from that file, I have to use a new file, temp.txt, which I write everything except the line that is deleted into. temp.txt is not getting this error
this is done in 3 methods, the same thing in each method

import java.util.*;
import java.util.regex.Pattern;
import java.time.*;
import java.io.*;
import java.text.*;
import java.time.temporal.ChronoUnit;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.io.FileNotFoundException;

public class input{
public LocalDate date1;

  public input (LocalDate date1){
    this.date1=date1;
  }

  public void getSubject(){
    try{
      
      long count= Files.lines(Paths.get("savedata.txt")).count();
      Scanner scanner= new Scanner(System.in);
      System.out.println("When you are done entering homework, enter 'done' at subject");

      FileWriter savedata = new FileWriter("savedata.txt", true);
      PrintWriter writer = new PrintWriter(savedata);
       
       
      Homework homework1= new Homework("empty", "2024-08-24");
      

      System.out.println("Enter the subject of the homework");
      homework1.subject= scanner.nextLine();


      
      if(homework1.subject.equals("done")){
        
        return;
      }
        
      
      
      
    writer.println(homework1.subject);

      writer.close();
    }catch(Exception c){
      c.printStackTrace();
      System.out.println("did not work");
    }
  }

  public void getDate() throws ParseException{

    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","2024-08-24" );

    //LocalDate.now()

    System.out.println("Enter the due date of the homework: YYYY-MM-DD");
    homework1.dueDate= scanner.nextLine();

    //LocalDate.parse
      
      while(homework1.dueDate!="done"){
        writer.println(homework1.dueDate);
        break;
      }
        
    while(homework1.dueDate.equals("done")){
      File oldfile = new File("savedata.txt");
      File newfile = new File("temp.txt");

      int line=0;
      String currentline;
      FileWriter fw= new FileWriter("temp.txt");
      BufferedWriter bw =new BufferedWriter(fw);
      PrintWriter pw= new PrintWriter(bw);

      FileReader fr= new FileReader("savedata.txt");
      BufferedReader br = new BufferedReader(fr);

      while((currentline=br.readLine())!=null){
        line++;
        if(count!=line){
          pw.println(currentline);
        }
      }

      pw.flush();
      pw.close();
      br.close();
      fw.close();
      bw.close();
      fr.close();

      oldfile.delete();
      File dump=new File("savedata.txt");
      newfile.renameTo(dump);
      
      break;
     }


       
       writer.close();
     

       
       
  }catch(Exception c){

  }

  
}

public void getArray(){
try{
  long count= Files.lines(Paths.get("savedata.txt")).count();
    Scanner scanner= new Scanner(System.in);
    FileWriter savedata = new FileWriter("savedata.txt", true);
   PrintWriter writer = new PrintWriter(savedata);
  Homework homework1= new Homework("empty", "2024-08-24");

  System.out.println("Enter parts of homework. Write done when done.");
     
    String finish="";

    while(finish.equals("done")){
      File oldfile = new File("savedata.txt");
      File newfile = new File("temp.txt");

      int line=0;
      String currentline;
      FileWriter fw= new FileWriter("temp.txt");
      BufferedWriter bw =new BufferedWriter(fw);
      PrintWriter pw= new PrintWriter(bw);

      FileReader fr= new FileReader("savedata.txt");
      BufferedReader br = new BufferedReader(fr);

      while((currentline=br.readLine())!=null){
        line++;
        if((count!=line)|| (count-1!=line)){
          pw.println(currentline);
        }
      }

      pw.flush();
      pw.close();
      br.close();
      fw.close();
      bw.close();
      fr.close();

      oldfile.delete();
      File dump=new File("savedata.txt");
      newfile.renameTo(dump);
      
      break;
    }
    while(!finish.equals("done")) {
      finish= scanner.nextLine();
      if(!finish.equals("done")) {
        parts newpart = new parts(finish);
        homework1.addPart(newpart);
      }
      }


       
      
      System.out.println(homework1.part);

      writer.println(homework1.part);
      

      writer.close();
    }catch(Exception c){

    }
}
}```

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.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật