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

  • Home
  • SEARCH
  • 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 109337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:03:13+00:00 2026-05-11T02:03:13+00:00

So my 2009 new years resolution is to learn Java. I recently acquired Java

  • 0

So my 2009 new years resolution is to learn Java. I recently acquired ‘Java for Dummies’ and have been following along with the demo code in the book by re-writing it using Eclipse. Anyway, every example in the book that uses a relative path does not seem to read the .txt file it’s supposed to read from.

Here is the sample code:

import java.util.Scanner; import java.io.File; import java.io.IOException; import javax.swing.JFrame; import javax.swing.JLabel; import java.awt.GridLayout;  class TeamFrame extends JFrame {      public TeamFrame() throws IOException {         PlayerPlus player;         Scanner myScanner = new Scanner(new File('Hankees.txt'));          for (int num = 1; num <= 9; num++) {             player = new PlayerPlus(myScanner.nextLine(), myScanner.nextDouble());             myScanner.nextLine();             addPlayerInfo(player);         }                add(new JLabel());         add(new JLabel('   ------'));         add(new JLabel('Team Batting Aberage:'));         add(new JLabel(PlayerPlus.findTeamAverageString()));         setTitle('The Hankees');         setLayout(new GridLayout(11,2));         setDefaultCloseOperation(EXIT_ON_CLOSE);         pack();         setVisible(true);     }      void addPlayerInfo(PlayerPlus player) {         add(new JLabel(player.getName()));         add(new JLabel(player.getAverageString()));     } } 

And you can see in the below screen shot I have included this file.

image no longer available

Also, I have verified that when I build the application that a copy of Hankees.txt is placed in the bin folder with the compiled .class files.

Lastly, if I change line 12 to the following and place Hankees.txt in the root of my C:\ drive the program compiles and runs fine.

Scanner myScanner = new Scanner(new File('C:\\Hankees.txt')); 

So basically, my question is what am I doing wrong? Or is Eclipse responsible for this in some way?

Thanks for any and all help!

  • 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. 2026-05-11T02:03:13+00:00Added an answer on May 11, 2026 at 2:03 am

    You need 'src/Hankees.txt'

    Your file is in the source folder which is not counted as the working directory.\

    Or you can move the file up to the root directory of your project and just use 'Hankees.txt'

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

Sidebar

Ask A Question

Stats

  • Questions 88k
  • Answers 88k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Why does each element of the _viewArray has to actually… May 11, 2026 at 5:40 pm
  • Editorial Team
    Editorial Team added an answer Here's a quote from the transcript wiki of podcast 51… May 11, 2026 at 5:40 pm
  • Editorial Team
    Editorial Team added an answer Yes, the event handler that throws the exception will stop… May 11, 2026 at 5:40 pm

Related Questions

I'm currently converting my site from PHP to Django, but as I'm new to
I want to be able to run an alert if the user does not
You know the one I am talking about. We have all been there at
I recently upgraded from Delphi 4 to Delphi 2009. With Delphi 4 I had

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.