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 8827139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:18:24+00:00 2026-06-14T07:18:24+00:00

So my question is just how the title goes. Below is a snippet of

  • 0

So my question is just how the title goes. Below is a snippet of my code. I understand that I’m supposed to use try/catch but in my catch, I’m not sure what to do in it. I’m getting an error /HERE/ saying that a BufferedReader cannot take in an InputStream. I want to continue using a BufferedReader, so is there any other class that I could instantiate w/in my new BufferedReader so that my compiler will be happy? Any help will be much appreciated, thank you!

    //reads in 'dictionary' file
    BufferedReader bReader;
    try
    {
        bReader = new BufferedReader
                (new FileReader("unsortedWords.txt"));
    }
    catch (FileNotFoundException e)
    {
        System.out.print("Enter name of dictionary file: ");
        bReader = new BufferedReader
                (new FileReader(System.in)); /*HERE*/
    }
  • 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-14T07:18:25+00:00Added an answer on June 14, 2026 at 7:18 am

    Maybe this:

    File file = new File("unsortedWords.txt");
    if(file.exists())
    {
     // do something
    }
    else
    {
     // prompt for file
     // if command line you can use Scanner or an InputStreamReader
     // if GUI you can use a File Chooser.
    }
    

    If you are unsure how to do the command line or GUI thing then just ask me and I will post the rest of the code.

    [EDIT]:
    I see you are doing the command line, so you can try this:

    InputStreamReader isr = new InputStreamReader(System.in);
    BufferedReader br = new BufferedReader(isr);
    String line = br.readLine();
    

    [EDIT]: Sample Class (yes it has bad design, but I wrote it quickly):

    import java.io.*;
    
    public class Temp
    {
    
        public static void main(String[] args) throws IOException
        {
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            System.out.println("Hello World!");
            String temp = br.readLine();
            System.out.println("Your line : \"" + temp + "\"");
        }
    }
    

    [EDIT]:
    Here is a class that I made which should work for you.

    import java.io.*;
    
    public class Temp
    {
    
        public static void main(String[] args) throws IOException
        {
            String fileName = "RandomFileThatDoesntExist";
            File file = new File(fileName);
    
            if(file.exists())
            {
                FileReader fr = new FileReader(fileName);
                BufferedReader br = new BufferedReader(fr);
                String line;
                while((line = br.readLine()) != null)
                {
                    System.out.println(line);
                }
            }
            else
            {
                InputStreamReader isr = new InputStreamReader(System.in);
                BufferedReader br = new BufferedReader(isr);
                System.out.println("Enter file Name:");
                String line;
                while(true)
                {
                    line = br.readLine();
                    File myFile = new File(line);
                    if(myFile.exists())
                        break;
                    else
                        System.out.println("Error, file doesn't exist!");
                }
                FileReader fr = new FileReader(line);
                BufferedReader br2 = new BufferedReader(fr);
                System.out.println("File contents:");
                while((line = br2.readLine()) != null)
                {
                    System.out.println(line);
                }
            }
        }
    }
    

    Screenshot:

    Screenshot of Command Line

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

Sidebar

Related Questions

Question is in the title. I'd just love to understand why this isn't supported?
Probably very simple question (I just want to ensure I'm right). Title is not
The question is just above the last code snippet. Thank you. (environment details are
There is an another question just about that, but I couldn't solve my problem
This is kind of a weird question so my title is just as weird.
Please do not mark it as a dupe of this question just yet: Bold
Newbie question: I just installed VisualSVN Server and created a repository. I noticed that
This might sound like a stupid question but just trying to learn something here.
I know the title of this question is a bit confusing, but here it
The question title just about says it all. I have a ASP.NET MVC 2

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.