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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:28:11+00:00 2026-06-10T08:28:11+00:00

Here is my code to read from a text file: public RecordManager(){ int pos;

  • 0

Here is my code to read from a text file:

    public RecordManager(){
    int pos;
    String athlete, record, country, raceTime;
    try {
        Scanner scFile = new Scanner(new File("resultdata.txt"));
        while(scFile.hasNext()){
            Scanner sc = new Scanner(scFile.next()).useDelimiter("#");
            athlete = sc.next();
            country = sc.next();
            pos = sc.nextInt();
            record = sc.next();
            raceTime = sc.next();                
            sc.close();
            if("WRC".equals(record)){
                resultArr[size] = new WorldRecord(athlete, country, pos, raceTime);
            }
            else if("OLR".equals(record)){
                resultArr[size] = new OlympicRecord(athlete, country, pos, raceTime);
            }
            else{
                resultArr[size] = new RaceResult(athlete, country, pos, raceTime);
            }
            size++;
        }
    } catch (FileNotFoundException ex) {
        Logger.getLogger(RecordManager.class.getName()).log(Level.SEVERE, null, ex);
    }

and here’s what’s in the text file:

Carey Blem#ITA#6#---#4m49.8 
Tammera Hoesly#POR#1#---#4m6.2 
Toi Swauger#FRA#1#OLR#51.3 
Moises Mellenthin#ZIM#2#---#4m34 
Madelene Mcclennon#LUX#1#WRC#1m52.7 
Lashon Meisenheimer#RSA#1#---#2m31.2

I have been trying and trying, but I just keep getting this:

run:
Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:907)
at java.util.Scanner.next(Scanner.java:1416)
at it.practical.training.RecordManager.<init>(RecordManager.java:29)
at it.practical.training.SimpleInterface.main(SimpleInterface.java:20)
Java Result: 1
BUILD SUCCESSFUL (total time: 13 seconds)

Please tell me what’s wrong.

  • 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-10T08:28:12+00:00Added an answer on June 10, 2026 at 8:28 am

    When you use next() it reads the next word. Your first line has two words Carey and Blem#ITA#6#---#4m49.8. When you have read words from a line you need to use nextLine() to go to the next line.

    I suspect what you really want is

    Scanner sc = new Scanner(scFile.nextLine()).useDelimiter("#");
    

    To read a whole line at a time.

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

Sidebar

Related Questions

I am trying to read all content from a text file. Here is the
I am running the following code to try and read from a text file.
I need to read certain statistics from iw_statistics structure, here's the code: struct net_device
I'm programming Java in Eclipse IDE. Here is code I want to read file:
Here is a simple piece of code: import java.io.*; public class Read { public
text = urllib.urlopen('www.text.com').read() frase = re.search(your text here(.*), text).group() With these code, I get
I want to read in data from a text file which is full of
Here's my code for reading my db data: OdbcDataReader rdr = cmd.ExecuteReader(); while (rdr.Read())
Here is what I got so far. Please read the comment in the code.
I want to get text from file, and show it on TextView sorted. I

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.