trying to read a file but doesnt know how to get the size of the inputstrem

hi im trying to read a file in a cel this is my code:

fconn = (FileConnection)Connector.open("file://localhost/" + actualdir);

InputStream fis = fconn.openInputStream();

byte b[] =newbyte[1024];

fis.read(b);

fis.close();

fconn.close();

textBox1 =new TextBox("Viendo el Archivo: " + list1.getString(list1.getSelectedIndex()), null, 1024,TextField.ANY | TextField.UNEDITABLE);

textBox1.setString(new String(b, 0, b.length));

i dont want to create always an array of bytes of size 1024 instead i wanna know how many bytes does inputstream object has, how can i know that?

[852 byte] By [eckoa] at [2007-11-27 2:06:19]
# 1
You can't know the size of the stream.Just use a stringbuffer to read to file in and convert it to string when the reading is done.
deepspacea at 2007-7-12 1:53:19 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 2
> You can't know the size of the stream.> > Just use a stringbuffer to read to file in and> convert it to string when the reading is done.i dont really know how to do that, could you please give me an example?....
eckoa at 2007-7-12 1:53:19 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 3

you can either retrieve the whole file at once by determine the file size like:

fconn = (FileConnection)Connector.open("file://localhost/" + actualdir);

InputStream fis = fconn.openInputStream();

byte b[] = new byte[fconn.fileSize()];

fis.read(b);

fis.close();

fconn.close();

or read every single byte

fconn = (FileConnection)Connector.open("file://localhost/" + actualdir);

InputStream fis = fconn.openInputStream();

ByteArrayOutputStream baos = new ByteArrayOutputStream();

int i = fis.read();

while(i != -1){

baos.write(i);

fis.read();

}

String content = new String(baos.toByteArray());

Markus.Schmitza at 2007-7-12 1:53:19 > top of Java-index,Java Mobility Forums,Java ME Technologies...