Hi,
I need to split an audio or large image file in J2ME before uploading it. How can i split/ break a file in to pieces in JavaME.
Regards,
Imran
Hi,
I need to split an audio or large image file in J2ME before uploading it. How can i split/ break a file in to pieces in JavaME.
Regards,
Imran
What API for file loading do you use?
1)If FileConnection API you can load data by blocks. There is no problem in this case.
2)If you use Class.getResourceAsStream( String pathInsideJar ) you will have problems. Most of KVMs load resource fully before returning control to your code. So I see one way - to split big file into several small files before creating jar.
DataInputStream dis = FileConnection.getDataInputStream();
byte[] buffer = new byte[2048];
int count;
int total = 0;
Vector v = new Vector();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
while( ( count = dis.read( buffer ) ) >= 0 )
{
total += count;
baos.write( buffer, 0, count );
if( total > 100000 )
{
baos.close(); byte[] data = baos.toByteArray(); v.addElement( data ); baos = new ByteArrayOutputStream(); }
}
So you will have Vector of several byte arrays. And you can send it one by one.
Or read all file data into one byte array and post this data by parts with shifting start position of sending data.