안드로이드

ByteArrayInputStream, ByteArrayOutputStream

raulyo 2012. 2. 22. 16:43
 FileInputStream fis = null;
        ByteArrayInputStream bais = null;
        ByteArrayOutputStream baos = null;
        
        try{
        fis = new FileInputStream("filepath");
        baos = new ByteArrayOutputStream();
        byte [] buffer = new byte[512];
        int readCount = 0;
        while((readCount = fis.read(buffer))!= -1){
        baos.write(buffer, 0 , readCount);
        }
       
        byte [] fileArray = baos.toByteArray(); 
       
        bais = new ByteArrayInputStream(fileArray);
        while((readCount = bais.read(buffer)) != -1){
        Log.d("myLog","buffer : " + buffer);
        }
        }catch (Exception e) {
// TODO: handle exception
}finally{
try{
fis.close();
bais.close();
baos.close();
}catch (Exception e) {
// TODO: handle exception
}
}