×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    9

    OutOfMemoryError while reading remote file

    Hi,
    i am trying to retrieve data from a file in a web site, the problem is that it works for small files (50 Kb for example), but it doesn't for "larger" files (over 200Kb). I get an OutOfMemoryError while reading the file if it's big.

    Actually i need to read two kinds of files from a server:
    1. text files that i have to parse to get the data, so i need to save all the data in memory for parsing, or parse while reading (but i think this might longer and that it's better to get the data, disconnect and then parse).
    2. data files (up to 300 kb) that i have to read and get the bytes to store in a RecordStore. These files just have to be stored, no treatment needed.

    Does the problem comes from the StringBuffer? Is there a limit to the buffer size ? Is it the emulator (i'm using NetBeans with the WTK) ?

    Here's the code i'm using:

    //================================
    InputConnection ic = null;
    InputStream is = null;
    StringBuffer sb = new StringBuffer();
    DataInputStream din = null;

    try {
    ic = (InputConnection)Connector.open(url, Connector.READ);
    is = ic.openInputStream();

    int ch;
    while((ch = is.read()) != -1)
    sb.append((char)ch);

    } catch (IOException ex) {
    ex.printStackTrace();
    }
    //================================

    I have tried to read the data by chunks of limited size, storing them, but again, i get the same error for larger files.

    Is there a better solution ?

    Thanks
    Last edited by a_nemoff; 2006-04-27 at 11:34.

  2. #2
    Registered User
    Join Date
    Apr 2006
    Posts
    9

    Re: OutOfMemoryError while reading remote file

    I found what the problem was. The problem was caused by the emulator Heap Size. Configuring it to at least 1Mb allowed to read all the data from the input stream.
    I also finally removed the chunk reading method because it made the data transfer slower, therefore the connection lasted longer.

Similar Threads

  1. Tips on using NDS 1.1
    By mitts in forum Symbian Tools & SDKs
    Replies: 7
    Last Post: 2006-01-18, 16:07
  2. Reading A Text File Woes
    By _nomad_ in forum Symbian
    Replies: 1
    Last Post: 2005-02-02, 10:09
  3. Series 60 SDK Appwizard on windows xp
    By moonjoor in forum Symbian Tools & SDKs
    Replies: 15
    Last Post: 2003-12-24, 10:22

Posting Permissions

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