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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:09:36+00:00 2026-05-28T07:09:36+00:00

am trying to read a file (double values) with scanner and save the data

  • 0

am trying to read a file (double values) with scanner and save the data into an array. until this point it working great. the strange that am trying to do is that i want to read certain values(the first 10) from the file, add them on the array, do something with those values and then read the next 10 values and continue doing it until the eof.
until now am only able to read once the first 10 values and can not read the second group of values.
the code that am using is:

File fi= new File(Environment.getExternalStorageDirectory().toString()+"/ECG/I.txt");  
scanner = new Scanner(fi);
scanner.useDelimiter(";");  
  int SAMPLE_SIZE=4;
    double timi[]= new double[SAMPLE_SIZE];
    for (int size=0; size<SAMPLE_SIZE; size++)
    {
    while(scanner.hasNext()&&size<SAMPLE_SIZE) {
       timi[size]=scanner.nextDouble();
       Log.i("File","String " + size +" "+timi[size]);
       size++;
      }
  • 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-28T07:09:37+00:00Added an answer on May 28, 2026 at 7:09 am

    Assuming your “read certain values (the first 10)” is your SAMPLE_SIZE (currently 4), you could do something like this:

    File fi = new File(Environment.getExternalStorageDirectory().toString() + "/ECG/I.txt");  
    scanner = new Scanner(fi);
    scanner.useDelimiter(";");
    
    int SAMPLE_SIZE = 4;
    double timi[] = new double[SAMPLE_SIZE];
    
    for(int sampleIdx = 0; scanner.hasNext();){
        timi[sampleIdx++] = scanner.nextDouble();
        Log.i("File", "String " + sampleIdx + " " + timi[sampleIdx]);
        if(sampleIdx == SAMPLE_SIZE){
            // Do something with the timi array here.
    
            sampleIdx = 0;
        }
    }
    

    This does not currently account for situations where the number of entries in the file is not a multiple of SAMPLE_SIZE. This could easily be extended to account for this situation, but is an exercise left to the reader – at least for now.

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

Sidebar

Related Questions

I'm trying to read a .doc file into a database so that I can
I am trying to read a text file using fscanf.I am working in eclipse
I'm trying to read some numbers (double) from a file and store them in
Here is my problem, I'm trying to read in data from a file beginningbalance.dat
I am trying to read in some values from a file in an octave
I am trying to read a Fortran double-precision number like 1.2345D+02 into python, but
I am trying to read from a file that has comma seperated values like
I am trying to read some data from a xml file, numbers are saved
I'm trying to read data in from a binary file and then store in
I'm trying to read a file to produce a DOM Document, but the file

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.