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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:14:32+00:00 2026-06-05T04:14:32+00:00

I’ve a text (file.txt) file . This file is loaded inside a scanner. In

  • 0

I’ve a text (file.txt) file . This file is loaded inside a scanner.

In the files there are various lines and in each line there are two doubles and one integer values divided by spaces.

Like this:

1.0 1.2 2
0.9 1.0 10
50.4 9.2 20

I need to fulfill three arrays.

Each array corresponds to a column. Something like:

double[] x = {1.0,0.9,50.4}
double[] y = {1.2,1.0,9.2}
double[] z = {2,10,20}

I tried to to this using this code:

        double x[]= new double [3];
        double y[]= new double [3];
        double z[]= new double [3];

        File f = new File(ClassLoader.getSystemResource(file.txt).toURI());
        Scanner sc = new Scanner(f);
        String aux;

        for (int i=0;i<3;i++){
               aux = sc.next();
               x[i] = Double.parseDouble(aux);
               aux = sc.next();
               y[i] = Double.parseDouble(aux);
               aux = sc.next();
               z[i] = Double.parseDouble(aux);
       }

but when the first Double.ParseDouble() I get “NumberFormatException”.

I did the debug and the variable aux has the value of a double (like: 1.0) so Double.parseDouble(aux) should works.

What it’s strange is that it says (when the exception is launched) that “aux” is something like ‘1.0 (with the ‘ before)

Is there any way to DELETE every symbol: like ‘ or , or . or “bom”(like “special spaces”) and so on? I mean.. without the need to specify the full list of possible symbols,because I don’t know the list of “invisible” symbols of a file (I mean: the symbols I can’t see when editing the file).

Thank you for any hint.

  • 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-05T04:14:34+00:00Added an answer on June 5, 2026 at 4:14 am

    Are you sure your file input is exactly like you are stating?

    I copied/pasted your exact file input into a file called “numbers.txt” and ran the class below. Seems to work exactly as intended:

    public class NumberParser
    {
        public static void parseData(String resourceName)
        {
            Scanner s = new Scanner(NumberParser.class.getResourceAsStream(
                 resourceName));
    
            double [] x = new double[3];
            double [] y = new double[3];
            int [] z = new int[3];
    
            for (int i = 0; i < 3; i++)
            {
                x[i] = s.nextDouble();
                y[i] = s.nextDouble();
                z[i] = s.nextInt();
            }
    
            System.out.println(Arrays.toString(x));
            System.out.println(Arrays.toString(y));
            System.out.println(Arrays.toString(z));
        }
    
        public static void main(String[] args)
        {
            parseData("numbers.txt");
        }
    }
    

    If your input is not exactly like you’ve stated (with commas, quotes, etc.) but basically numbers separated by these marks you could make your delimiter (the stuff between meaningful tokens) anything but the stuff you are looking for:

    public static void parseMessedUpData(String resourceName)
    {
        Scanner s = new Scanner(NumberParser.class.getResourceAsStream(
            resourceName));
        s.useDelimiter("[^0-9.]++"); // <-------
    
        double [] x = new double[3];
        double [] y = new double[3];
        int [] z = new int[3];
    
        for (int i = 0; i < 3; i++)
        {
            x[i] = s.nextDouble();
            y[i] = s.nextDouble();
            z[i] = s.nextInt();
        }
    
        System.out.println(Arrays.toString(x));
        System.out.println(Arrays.toString(y));
        System.out.println(Arrays.toString(z));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a reasonable size flat file database of text documents mostly saved in
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
In my XML file chapters tag has more chapter tag.i need to display chapters

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.