public byte[] getTypeOta(byte[] fileBytes){
//byte[] otaBytes = convertCode(fileBytes);
byte[] typeOtaByte = new byte[fileBytes.length+1];
typeOtaByte[0]='S';
System.out.println("otaBytes[0]"+Integer.toHexString(fileBytes[0]));
for (int i = 1; i < typeOtaByte.length; i++) {
typeOtaByte[i]=(byte)(fileBytes[i-1]);
}
// System.out.println("fileBytes="+fileBytes.length);
//System.out.println("typeOtaByte"+typeOtaByte.length);
return typeOtaByte;
} /*
 * reWrite the method getTypeOta
 */
public byte[] getTypeOta(byte[] upfile,byte[] totalBytes){
totalBytes[16]='S';
int j=0;
for (int i = 17; i < totalBytes.length; i++) {
totalBytes[i]=upfile[j];
j=j+1;
}
return totalBytes;
}

解决方案 »

  1.   

    帮你整理了一下,否则太乱了,看的人就会少的,呵呵 :)public byte[] getTypeOta(byte[] fileBytes) { 
        //byte[] otaBytes = convertCode(fileBytes); 
        byte[] typeOtaByte = new byte[fileBytes.length + 1]; 
        typeOtaByte[0] = 'S'; 
        System.out.println("otaBytes[0]" + Integer.toHexString(fileBytes[0])); 
        for (int i = 1; i < typeOtaByte.length; i++) { 
            typeOtaByte[i] = (byte)(fileBytes[i - 1]); 
        }
        // System.out.println("fileBytes = " + fileBytes.length); 
        //System.out.println("typeOtaByte" + typeOtaByte.length); 
        return typeOtaByte; 
    } /**
     * reWrite the method getTypeOta 
     */ 
    public byte[] getTypeOta(byte[] upfile, byte[] totalBytes) { 
        totalBytes[16] = 'S'; 
        int j = 0; 
        for (int i = 17; i < totalBytes.length; i++) { 
            totalBytes[i] = upfile[j]; 
            j = j + 1; 
        }
        return totalBytes; 
    }
      

  2.   

    看的我好晕啊...至少也说一下你的方法大意啊   我看着好像是吧一个byte数组倒序输出到另一个数组你去  是吗?第一个方法参数是源数组  第二个方法是源数组和目标数组作为参数   就这点差别吧?  我觉得各有好坏吧  
    第一种的话   typeOtaByte是局部变量  第二种的话totalBytes是类的变量了  需要在类中申明了
      

  3.   

    好象是把一个数组第一位置成'S',其他的后移。public byte[] getTypeOta(byte[] fileBytes) 
    {
         String soc = String.valueOf(fileBytes);
        
         String des = "s"+soc;
        
         return des.getBytes();
    }
      

  4.   

    目的是要频繁改变数组内容的功能。一个新的数组增加好几次内容(最后的数组长度可以确定)。
    每次增加的时候都new一个新的数组合适,还是直接new 最终长度的数组,直接向这个数组赋值n次合适?上述两个方法的意思:
    我的意思是给数组赋值的效率哪个高。第一个方法是new 一个新的数组,然后把要赋值的数据复制到这个数组中去;
    第二个方法是
      

  5.   

    我看拉也是很糊涂,不过听你这么一解释,明白点,这有什么可比较效率的,
    没考虑过new与固定数组的区别  
    我也顶啦