• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

J2ME FileConnection

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My program opens a file and reads it using the following code:

fc = (FileConnection)Connector.open(file.getString());
fis = fc.openInputStream();
fdi = new DataInputStream(fis);

int inputChar2;
String strTar = new String();
while ( (inputChar2 = fdi.read()) != -1) {
strTar+=((char)inputChar2);
}
fdi.close();
fis.close();
fc.close();

After the file is read, I store it in a String and open a second file, then I replace the previous String with the second file, and open a third file, etc. So, I keep updating a String with files that are all about 40 kilobytes. When I am trying to read the second file that I open (in the loop), I get an out of memory exception. How can I fix this? It doesn't make sense to me because I can always open the first file, no matter how big it is. But, after I store the first file into a String and then open and try to read the second file, I get the following exception. Please help! How can I fix this and why is it doing it?

java.lang.OutOfMemoryError
at javax.microedition.lcdui.Display$DisplayAccessor.commandAction(+309)
at javax.microedition.lcdui.Display$DisplayManagerImpl.commandAction(+10)
at com.sun.midp.lcdui.DefaultEventHandler.commandEvent(+68)
at com.sun.midp.lcdui.AutomatedEventHandler.commandEvent(+47)
at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.run(+250)
 
reply
    Bookmark Topic Watch Topic
  • New Topic