×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    21

    Read and display large files

    Hi,
    I need to display the contents of a large file (about 2MB). For small files I used to read the file through an InputStream and then use a TextBox to display the StringBuffer like this:

    Code:
    StringBuffer sb = new StringBuffer();
    InputStream is = fc.openInputStream();
    int bytesRead;
    while ((bytesRead = is.read()) != -1) {
      sb.append(bytesRead); 
    }
    viewFile = new TextBox("View File:", null, 90000,
                TextField.ANY | TextField.UNEDITABLE);
    viewFile.setString(sb.toString());
    This works fine for small files, but unfortunately I had to find out that a TextBox throws a out of memory exception at about a 90000 byte size in the emulator. On a real phone this also does not work.

    So my question is how can I display the content of such large files. Is it possible to get all the data on the screen and then scroll through it like in small files?

    Best regards,
    Hak
    There are only 10 types of people in the world: Those who understand binary and those who don't.

  2. #2
    Registered User
    Join Date
    Nov 2009
    Posts
    188

    Re: Read and display large files

    Quote Originally Posted by Hak View Post
    Hi,
    I need to display the contents of a large file (about 2MB). For small files I used to read the file through an InputStream and then use a TextBox to display the StringBuffer like this:

    Code:
    StringBuffer sb = new StringBuffer();
    InputStream is = fc.openInputStream();
    int bytesRead;
    while ((bytesRead = is.read()) != -1) {
      sb.append(bytesRead); 
    }
    viewFile = new TextBox("View File:", null, 90000,
                TextField.ANY | TextField.UNEDITABLE);
    viewFile.setString(sb.toString());
    This works fine for small files, but unfortunately I had to find out that a TextBox throws a out of memory exception at about a 90000 byte size in the emulator. On a real phone this also does not work.

    So my question is how can I display the content of such large files. Is it possible to get all the data on the screen and then scroll through it like in small files?

    Best regards,
    Hak
    In which emulator/device you are trying to do?

    If you are trying in the emulator provided by the netbeans which has 2MB heap memory or in the device having the heap memory as 2MB then you can not display the content of a large files of size about 2MB. It will give out of memory exception.As other part of your application are taking some memory.

    If you want to display large files then you have to check with the higher end devices where the heap memory should be more than 2MB.

    Thanks & Regards,
    Ajit

  3. #3
    Super Contributor
    Join Date
    Mar 2003
    Location
    Finland
    Posts
    9,556

    Re: Read and display large files

    However, you could of course only read part of the file, remember the offset, and when required, read more from that offset ahead, and so on (including going backwards, if the application user so decides).

  4. #4
    Registered User
    Join Date
    Nov 2009
    Posts
    188

    Re: Read and display large files

    Quote Originally Posted by petrib View Post
    However, you could of course only read part of the file, remember the offset, and when required, read more from that offset ahead, and so on (including going backwards, if the application user so decides).
    I think This is the best solution for your problem.
    You can read a part of the file and display.

    Thanks & regards,
    Ajit

Similar Threads

  1. Recording in Amr Format
    By losym in forum Symbian Media (Closed)
    Replies: 12
    Last Post: 2009-03-26, 06:41
  2. Really need help..about canvas to read a large text file
    By thetoppy in forum Mobile Java General
    Replies: 2
    Last Post: 2008-03-07, 12:08
  3. How to read Name Display Setting?
    By twarna in forum Symbian
    Replies: 3
    Last Post: 2008-02-18, 13:21
  4. read file and display contents
    By sajindra in forum Symbian
    Replies: 0
    Last Post: 2004-05-16, 18:55

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×