-2

I have tried doing this but it always give of an error: unreported exception IO exception; must be caught or declared to be thrown. but then if I try putting a try catch in the write, newLine, flush, my main program would have the same error.

public Course(){
    try{
        fw = new FileWriter("Something.txt", true);
        bWrite = new BufferedWriter(fw);
        file = new File("Someting.txt");
        scanner = new Scanner(file);
    }catch(Exception e){}
}

public void setDetails(String cID, String cName)throws Exception{
    write = cID + " || " + cName;
    bWrite.write(write);
    bWrite.newLine();
    bWrite.flush();
}

1 Answers1

1

SetDetails() says that it throws an exception. That means wherever we call SetDetails() there needs to be a catch clause.

Also look into chained exceptions.

MackProgramsAlot
  • 583
  • 1
  • 3
  • 16