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

Reply With Quote

