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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:00:39+00:00 2026-06-12T13:00:39+00:00

I have a file that I put some numbers into but then I decided

  • 0

I have a file that I put some numbers into but then I decided I wanted to label the numbers with a name for each one, like so:

A = 1 2 3
B = 3 4 5
C = 6 7 8

This caused an exception to be thrown. I want to know how I can workaround this so the scanner ‘ignores’ all but the numbers unless I tell it otherwise.

Can anyone help?

EDIT:

Also, I already know what is causing the exception. I am using next.Double(); to pick out the numbers in the file.

public static void readFile() throws IOException, FileNotFoundException {

    String fileName = "vectors.txt";


    // Reference the file using the the BufferedReader object
    BufferedReader input = new BufferedReader(new FileReader(fileName));    

    //scanner to scan through file 
    Scanner token = new Scanner(input);

    double fileX = token.nextDouble();
    double fileY = token.nextDouble();
    double fileZ = token.nextDouble();

    vecA = new Vector3D(fileX,fileY,fileZ);

    fileX = token.nextDouble();
    fileY= token.nextDouble();
    fileZ = token.nextDouble();

    vecB = new Vector3D(fileX, fileY, fileZ);

    fileX = token.nextDouble();
    fileY= token.nextDouble();
    fileZ = token.nextDouble();

    //initialize vecC using double values from third line of file
    vecC = new Vector3D(fileX, fileY, fileZ);


    //close file 
    input.close();


}
  • 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-12T13:00:41+00:00Added an answer on June 12, 2026 at 1:00 pm

    You cannot make the scanner ignore input automatically, but you can write code to skip input yourself until you see that a double is available:

    while (!scanner.hasNextDouble()) {
        scanner.next();
    }
    double d = scanner.nextDouble();
    

    If you need to put this code in multiple places, you can wrap it in a function:

    private static double skipAndGetDouble(Scanner scanner) {
        while (scanner.hasNext() && !scanner.hasNextDouble()) {
            scanner.next();
        }
        return scanner.hasNextDouble() ? scanner.nextDouble() : Double.NaN;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have text file with some stuff that i would like to put into
I have a jar file that I want to put in the shared lib
I have a php file that looks like this: <?php include(config.php); // put the
I have a program that reads a file, treat it and put the results
I have a file that has the following format: 12345 TAB_HERE Name : The
We have some feature branches that can get put on ice for a few
I have a dataframe in R that I loaded from a CSV file. One
Hi I have a text file which contains some numerical data. Of that text
Ok so basically I have this text file with numbers and letters that's supposed
I have a File that COntains Strings in This Format: ACHMU)][2:s,161,(ACH Payment Sys Menus

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.