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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T17:26:33+00:00 2026-05-29T17:26:33+00:00

i have implement a small code of reading from a file with scanner and

  • 0

i have implement a small code of reading from a file with scanner and save the values on an array. am reading 3-6 files the same time and save the numbers in 3-6 arrays. the files are saved on the sdcard of my phone. my problem is that is slow reading all thoses and it took a long time until it finish. how i can re-write the code in order to be more efficient, or the files should be saved on the poject and when i install the application on the device to install the files and access them from there

the code that am usgin is the below:

try {

 File I= new File(Environment.getExternalStorageDirectory().toString()+"/ECG/test/I.txt");  
 scannerI = new Scanner(I);
 scannerI.useDelimiter(";"); 
 for(int sampleIdx = 0; scannerI.hasNext();){
 timiI[sampleIdx] = scannerI.nextDouble();
 sampleIdx++;

 if(sampleIdx == SAMPLE_SIZE && !Thread.currentThread().isInterrupted()){
 //do something
 sampleIdx = 0;
                    }
                }           
           }
}

as i mention and before am using more than 1 files, and the according arrays

  • 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-29T17:26:35+00:00Added an answer on May 29, 2026 at 5:26 pm

    Scanner is slow in Android in my experience.

    I improved my application responsiveness by

    1. Moving the parsing code into an AsyncTask (http://developer.android.com/reference/android/os/AsyncTask.html) and running the file reading in a background thread.
    2. Using LineNumberReader and String.split(“;”) instead of Scanner.

    The 2nd hint sped things up in my app by about 10x, but was still too slow to avoid an ANR, hence the background task.

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

Sidebar

Related Questions

I have many small files containing code fragments, pseudo-code algorithms, classes, templates, SQL-samples, etc.,
I have to implement a middleware system for file sharing, and it has to
Let's say I have to implement a piece of T-SQL code that must return
I have to implement a small feature in an iPhone app and was wondering
I have written a code for joining two wave files.It works fine when i
I am parsing binary files and have to implement a CRC algorithm to ensure
I have to document a small piece of code (a game), and document the
I have a small issue with iAP. I have the code working for the
I have a small bit of code that runs in an applet that contains
I have the following code snippet of a small Thread class I am trying

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.