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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:35:33+00:00 2026-06-12T04:35:33+00:00

I’ve a big txt file (1.5 Mb) as private resource in my Android Application.

  • 0

I’ve a big txt file (1.5 Mb) as private resource in my Android Application.
The file is structured like this:

"A1|A2|A3|A4#B1|B2|B3|B4#C1|C2|C3|C4#..."

where A1, A2, A3, B1… are alphanumerical strings. I need to create an object for each group of strings, something like this:

MyObject objA = new MyObject("A1", "A2", "A3", "A4");
MyObject objB = new MyObject("B1", "B2", "B3", "B4");
...

I’ve developed a reader class in order to read this file… but it looks a bit slow.
Here it is:

public class TextFileReader {

    private static Charset charset = Charset.defaultCharset();
    private InputStream stream;
    private InputStreamReader reader;
    private StringBuffer buffer;

    public TextFileReader(Context c, String s) {
        try {
            this.stream = c.openFileInput(s);
            this.reader = new InputStreamReader(this.stream, charset);
            this.buffer = new StringBuffer();
        } catch (FileNotFoundException e) {
        }
    }

    public String readNextSubstring(char div) throws IOException {
        buffer.delete(0, buffer.length());
        int i;
        char c;
        while ((i = reader.read()) > -1) {
            c = (char) i;
            if (c == div) break;
            buffer.append(c);
        }
        return buffer.toString();
    }
}

I use TextFileReader in this way:

TextFileReader reader = new TextFileReader(context, "big_file.txt");

//First group
String group = reader.readNextSubstring('#');
String[] info = group.split("\\|");
MyObject objA = new MyObject(info[0], info[1], info[2], info[3]);

//Second group
group = reader.readNextSubstring('#');
info = group.split("\\|");
MyObject objB = new MyObject(info[0], info[1], info[2], info[3]);

//Obviously this is done in a while loop :)
...

What do you think about this method? Could it be structured in a more efficient way?
I don’t care about space, I care about time (the emulator takes a LOT of time in order to read the file)

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

    I can find one simple tweak that can speed you up simply by improving how much time you spend on doing this: group.split("\\|");

    The way java does it is that for each time you run this line, it will compile a new regex.

    If you do this:

    Pattern pattern = Pattern.compile("\\|");
    TextFileReader reader = new TextFileReader(context, "big_file.txt");
    
    while (reader.hasMoreData) 
    {
      String group = reader.readNextSubstring('#');
      String[] info = pattern.split(group);
      MyObject objA = new MyObject(info[0], info[1], info[2], info[3]);
      ...
    }
    

    This will reduce the time it takes to compile the pattern – which can be quite considerable for your amount of data.

    Also, 1.5MB is not that much, perhaps loading it all to memory using a BufferedReader will probably improve your performance even more.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
In my XML file chapters tag has more chapter tag.i need to display chapters
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

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.