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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:28:54+00:00 2026-05-22T21:28:54+00:00

As per this link below: http://java.sun.com/developer/technicalArticles/Programming/PerfTuning/ You can speed up loading of bitmaps (or

  • 0

As per this link below:

http://java.sun.com/developer/technicalArticles/Programming/PerfTuning/

You can speed up loading of bitmaps (or any files) if you do the buffering yourself (i.e., instead of using BufferedInputStream, you handle the buffering yourself).

In particular, Approach 4 looks promising (slurp whole file at a time). However, I have no idea how to implement that in android. Here’s the Java code:

import java.io.*;

public class readfile {
 public static void main(String args[]) {
  if (args.length != 1) {
    System.err.println("missing filename");
    System.exit(1);
  }
  try {
    int len = (int)(new File(args[0]).length());
    FileInputStream fis =
        new FileInputStream(args[0]);
    byte buf[] = new byte[len];
    fis.read(buf);
    fis.close();
    int cnt = 0;
    for (int i = 0; i < len; i++) {
      if (buf[i] == '\n')
        cnt++;
    }
    System.out.println(cnt);
  }
  catch (IOException e) {
    System.err.println(e);
  }
 }

}

  • 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-22T21:28:54+00:00Added an answer on May 22, 2026 at 9:28 pm

    This technique is not optimized for Android and will likely run poorly. The convention is to use AndroidHttpClient:

    Subclass of the Apache DefaultHttpClient that is configured with reasonable default settings and registered schemes for Android, and also lets the user add HttpRequestInterceptor classes.

    If you really want to use Sun’s code above, you should be careful because you will likely exceed the VM heap budget when the size of the file exceeds the amount of heap space available to the application.

    It would be wise to first check if there is sufficient heap space left using ActivityManager. See also the elaborate answer to this question.

    Edit:

    I’ve found an example of sending an InputStream via POST. Here a file is being read from a resource (res/data.xml), but you could replace the InputStream with the FileInputStream from your snippet. Converting the InputStream to a byte array does essentially the same as your code: read the entire file into memory and push it into the request. This is a notorious cause of OutOfMemoryErrors, so take care that you don’t read files that are too large (I would suggest less than 1 MB).

    public void executeMultipartPost() throws Exception {
        try {
            InputStream is = this.getAssets().open("data.xml");
            HttpClient httpClient = new DefaultHttpClient();
            HttpPost postRequest = new HttpPost("http://w3mentor.com/Upload.aspx");
            byte[] data = IOUtils.toByteArray(is);
            InputStreamBody isb = new InputStreamBody(new ByteArrayInputStream(data),"uploadedFile");
            StringBody sb1 = new StringBody("someTextGoesHere");
            StringBody sb2 = new StringBody("someTextGoesHere too");
            MultipartEntity multipartContent = new MultipartEntity();
            multipartContent.addPart("uploadedFile", isb);
            multipartContent.addPart("one", sb1);
            multipartContent.addPart("two", sb2);
            postRequest.setEntity(multipartContent);
            HttpResponse res = httpClient.execute(postRequest);
            res.getEntity().getContent().close();
        } catch (Throwable e) {
            // handle exception here
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently ran the database repair tool as per this link: http://www.magentocommerce.com/wiki/1_-_installation_and_configuration/db-repair-tool At the
My q and a page sucks - it's this: http://rankingclimber.com/qa.php I checked out http://www.text-link-ads.com/r/faq
Per this helpful article I have confirmed I have a connection pool leak in
Per this question (see comments near the bottom), I was wondering if anyone knows
As per this MSDN article: W3C Extended Log File Format (IIS 6.0) It says
I need to have a single instance application (as per this answer ), but
I'm trying to build a Synergy AutoStart script as per this article , the
I am putting a label on a UIToolbar (per this tip: Adding a UILabel
I've set up multiple ssl sites on iis using Servier Bindings as per this
I'm trying to add a publisher policy file to the gac as per this

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.