Not able to write to file

Hi all,

I need to upload a file from a J2ME device to a remote server using a servlet

I am uploading an image ..and in the servlet i get the size of the file but i am not able to write to that file...please see code below...any help would be great.

Thanks in advance

StringBuffer bufferBody=new StringBuffer();

String line="";

byte[] data = new byte[79872000];

int cnt=0;

try

{

BufferedReader body=request.getReader();

while ((line = body.readLine()) != null) {

bufferBody.append(line);

cnt++;

}

data = bufferBody.toString().getBytes();

System.out.println("data received:"+data+"data length:"+data.length+"lines"+cnt);

String newFileName = "/home/aztec/pic2.jpg";

//data="hi".getBytes();

FileOutputStream imageOutput = new FileOutputStream(new File(newFileName));

imageOutput.write(data, 0, data.length);

imageOutput.close();

System.out.println("Please find image in " + newFileName);

} catch(Exception ex) {

System.out.println("Exception: " + ex);

ex.printStackTrace();

}

[1135 byte] By [venuwina] at [2007-11-27 9:37:49]
# 1
Don't use text stream I/O for binary data, i.e. image.
hiwaa at 2007-7-12 23:09:51 > top of Java-index,Java Essentials,Java Programming...
# 2
And don't read entire files into memory, especially in a memory-constrained J2ME device. Read and write a 4k chunk at a time.
ejpa at 2007-7-12 23:09:51 > top of Java-index,Java Essentials,Java Programming...