你好,我现在在写接口,要把文件打包以二进制流的形式传输 我想获得二进制流的长度,但是获得的二进制流的长度和报文中返回错误码中长度不一致,请问怎么获得二进制流长度(在这里的二进制长度我写死了,假如要是不写死的话该怎么写呢)sFilePath= "D:\\Upload";
sFileName="D:\\Upload\\测试用例.doc";
String sTr = "";
int canread = 0;
FileInputStream is = null;
        FileInputStream _is = null;
 try {
is = new FileInputStream(sFileName);
            String fileName =sFileName;
            
            String[] zipfile = fileName.split(";");
if (zipfile.length>=1){
fileName = Zip.zip(zipfile);
}
            _is = new FileInputStream( fileName );
           canread = _is.available();
           dContentCount =canread;
           System.out.println("------------输出字符长度-------------"+dContentCount);
           byte[] a = new byte[canread];
           _is.read( a );
           sTr = new BASE64Encoder().encode( a );
           
           System.out.println("------------输出字符长度-------------"+sTr.length());
} catch (Exception e) {
e.printStackTrace();
}


StringBuffer sb = new StringBuffer( "" );

//报文体类型  -----------100000021clientNo|201101182082
//报文体每个字段 有 1+8位的字段长度不足8位补零+字段名称+|+字段值

String sClientNo = "clientNo|201101182082";
String sEndClientNo = getStringAddValue(Integer.toString(sClientNo.length()),"0",8,"Before");//计算字段长度并且把不足8位的前面补零
sEndClientNo = "1"+sEndClientNo+sClientNo;

String sfileName = "fileName|测试用例.zip";
String sEndFileName = getStringAddValue(Integer.toString(sfileName.length()),"0",8,"Before");
sEndFileName = "1"+sEndFileName+sfileName;

String sContent = "content|"+sTr;
String sEndContent = getStringAddValue(Integer.toString(sContent.length()),"0",8,"Before");
sEndContent = "00024846";
sEndContent = "1"+sEndContent+sContent;

String sBodyStr = sEndClientNo+sEndFileName+ sEndContent;
String sBodyCount = getStringAddValue(Integer.toString (("content|"+sEndClientNo+sEndFileName).length()+sTr.length()/8)," ",6,"Before");

System.out.println("----------二进制未转换字符长度后-------------"+sTr.length());
System.out.println("----------二进制未转换字符长度后-------------"+"100000021clientNo|201101182082100000021fileName|测试用例.doc.zip".length());
System.out.println("----------二进制转换成字符长度后-------------"+(sTr.length()/8));
System.out.println("----------除去二进制后的长度-------------"+(("content|"+sEndClientNo+sEndFileName).length()+26));
sb.append( "00ENGINE001               ");//报文头
sb.append(" 24911");//报文头中报文体长度,长度六位,不足六位不空格
sb.append(sBodyStr);
sTr = sb.toString();
System.out.println("------------------------"+sTr);
    return sTr;