Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8298403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:45:33+00:00 2026-06-08T15:45:33+00:00

I am trying to write to a file. I have declared an exception in

  • 0

I am trying to write to a file.

I have declared an exception in the method writeHtmlFile, but the error “unreported exception java.io.IOException must be caught or declared to be thrown” keeps appearing anyway when I try to call on the writeHtmlFile method?

public class PartB extends ChangeDrawer
{

  public static ChangeDrawer cd = new ChangeDrawer();
  static int[] floatDrawer = {8,5,4,4,5,20,20,6,10,3,8};

   {
      String selection="";
      Scanner scan = new Scanner (System.in); 

      System.out.println ("Enter P to make a purchase and receive your change");
      System.out.println ("Enter L to load the Change drawer");
      System.out.println ("Enter H to write the contents of the Change Drawer to a web page");
      System.out.println ("Enter E to exit the program");


    while (selection.compareTo("E")!=0)
    {
      selection = scan.next();
      if (selection.compareTo("P")== 0)
         makeChange();
      else if (selection.compareTo("L")==0)
         loadFloat();
       else if (selection.compareTo("H")==0)
         writeHtmlFile(); //unreported exception java.io.IOException must be caught or
                          //declared to be thrown


    }
        System.out.println ("Ending .............................. ");
    }


    //more code exists between these two sets

   public static void writeHtmlFile() throws IOException
   {
    FileWriter fwriter = new FileWriter("ChangeDrawer.html");
    PrintWriter outputFile = new PrintWriter(fwriter);
    outputFile.println("This should work!");

  }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T15:45:35+00:00Added an answer on June 8, 2026 at 3:45 pm

    The code that calls writeHtmlFile must catch (or redeclare to be thrown) the IOException. Since the calling code is in a static initializer, it must be the former.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to write a custom .screenrc file TEST as follows startup_message
I have been trying to write some code in Scala to read a file
I have a binary file to which I'm trying to write however I dont
I'm trying to write a multi-file patch for an open-source project, but the master
I am trying to write an array to file, where I have opened the
i'm trying to create a Random Access file in java. I write something in
I have a StringIO() file-like object, and I am trying to write it to
I am trying to write a program using python-fuse, but I can't get file
I am trying to write an uploaded multipart file to the filesystem. I have
I'm trying to write a tokenizer, but I'm getting a parse error: %*************************** parse

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.