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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:04:42+00:00 2026-05-31T13:04:42+00:00

So I have the following code to check for the text file called Doctors.txt

  • 0

So I have the following code to check for the text file called Doctors.txt

It has the following information:

35000   2000    AV122258C   Dr Alex James   CARDIO
30500   2005    AB347433C   Miss Elizabeth Kooper   MB
32653   1995    JA103240B   Dr Mohammed Khan    ON
64400   2001    JG371458A   Dr Tom Jacob    CARDIO
91000   2002    IH102411Y   Dr Rahana Mohammed  ON 
55000   1987    JJ405626N   Dr Mary Francis AN
87000   1988    WQ333452N   Mr Mark Cromwell    NEURO
60500   1998    HK413942S   Mr Victor Jacob GASTRO
40000   2003    AJ103006X   Dr Mia Larson   GS
42000   2003    ER148468D   Dr Rizwan Hussain   GS
38000   2004    RB193984P   Dr Lam Yeng HAE

The class file it self…

import java.io.PrintWriter;
import java.io.FileReader;
import java.util.Scanner;
import java.io.IOException;

public class FileHandler
 {
/**
 * Save all doctor records to a file
 * @param doctors  the DoctorList to save
 */
public void saveRecords(DoctorList doctors)
{  
      PrintWriter writer = null;
    try
    {   // NB: the file name is hard-coded
        writer = new PrintWriter("Doctors.txt");
        writer.println(doctors.toString());
        writer.flush();
    }
    catch(IOException e)
    {
        System.out.println("Error writing file");
    }
    finally
    {
        writer.close();
    }
}

/**
 * Load doctor records from the file
 * @param doctors  the DoctorList to add doctors to
 */
public void readRecords(DoctorList doctors)
{
    FileReader reader = null;
    try
    {
       // NB: the file name is hard-coded
        reader = new FileReader("Doctors.txt");
        Scanner sc = new Scanner(reader);

        String record;
        String[] data;
            Doctor doctor;
        while(sc.hasNextLine())
        {
            record = sc.nextLine();
            if(record.length() != 0)
            {
                data = record.split("\t", 5);
                      doctor = DoctorFactory.newDoctor(data[3], data[0], data[2], data[1], data[4]);
                doctors.add(doctor);
            }
        }
    }
    catch(IOException e)
    {
        System.out.println("Error reading file");
        e.printStackTrace();
    }
 }
}

I’ve put it within the same area like so:
enter image description here

However it seems that when I run the main class, it cannot read the contents…

  • 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-05-31T13:04:43+00:00Added an answer on May 31, 2026 at 1:04 pm

    The path is your problem. Try this:

     reader = new FileReader("src/Doctors.txt");
    

    A better solution is to not rely on file paths and use getResourceAsStream() to return an InputStream from the CLASSPATH.

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

Sidebar

Related Questions

I have following task to do: to fill spell check dictionary (simple txt file)
I have the following code: foreach (ListItem item in check.Items) { if (item.Selected) {
I have the following piece of code where check is for char type do{
I have the following jQuery code in my PHP file (edited Jan 19 2010
I have the following JQuery code that parse an XML file just they way
I have the following code which check password/login and do other actions: public virtual
I have following code in my application: // to set tip - photo in
I have following code in my Application. Comments in my code will specify My
I have following code in my application. [self.navigationController pushViewController:x animated:YES]; It will push a
I have following code class User attr_accessor :name end u = User.new u.name =

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.