如何从黑莓中的音频文件中获取字节。我使用了文件选择器并上传了音频。 我试过了 -
FileConnection fc= (FileConnection)Connector.open(sel);
InputStream is=fc.openInputStream();
ReimgData = IOUtilities.streamToBytes(is);
我必须使用任何编码方法吗?。
在图像编码上,我们使用以下代码进行编码
EncodedImage encode_image =EncodedImage.createEncodedImage(ReimgData, 0, (int)fc.fileSize());
JPEGEncodedImage encoder=JPEGEncodedImage.encode(encode_image.getBitmap(),50);
byte[] array=encoder.getData();
// Decodes the image represented by this EncodedImage and returns a Bitmap
int length=array.length;
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(length);
Base64OutputStream base64OutputStream = new Base64OutputStream( byteArrayOutputStream );
try{
base64OutputStream.write( array, 0, length );
base64OutputStream.flush();
base64OutputStream.close();
}
catch (IOException ioe){
//Dialog.alert("Error in encodeBase64() : "+ioe.toString());
System.out.println("Error in encodeBase64() : "+ioe.toString());
}
//----Decoding image
try
{
System.out.print(byteArrayOutputStream.toString());
//Dialog.alert(byteArrayOutputStream.toString()+"");
data = Base64InputStream.decode(byteArrayOutputStream.toString());
答案 0 :(得分:0)
您可以按如下方式读取音频文件(或任何文件)中的字节:
FileConnection file = (FileConnection)Connector.open("yourfile.mp3");
InputStream audioStream = file.openInputStream();
byte[] audioData = IOUtilities.streamToBytes(audioStream);
audioStream.close();
file.close();