enumeration E=filesystemregistry.listroots ();//Get File path
String root = (string) e.nextelement ();
String url= "file:///" +root+filename;
fileconnection conn=null;
try{
conn= (fileconnection) Connector.open (Url,connector.read); Open a text file
DataInputStream In=conn.opendatainputstream (); Open Data input stream
int size=in.available (); Check text file size
System.out.println (size);
byte[] Buffer=new byte[size]; Creating a text buffer
in.read (buffer); Read all content into the buffer
string Content=new string (buffer,encoding); Create a string with the contents of the buffer
content=content.substring (1);
Buffer=null; Releasing buffers
In.close (); Turn off the data entry stream
Conn.close (); Close a text file
In=null;
.....
int size=in.available (); Gets the size of 0, but if you manually set the buffer size, is able to read the data of the file, then the input stream should be normal, but why in.available () can not get the size of the input stream,
if you just want to get the file size. can be used directly with int size= (int) conn.filesize () ; Inputsteam available () method returns 0 forever if not overridden. FileInputStream realized the available () method, you can get the value
Questions about the available () method in InputStream