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;
}
//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;
}
//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;
}
第一种的话 typeOtaByte是局部变量 第二种的话totalBytes是类的变量了 需要在类中申明了
{
String soc = String.valueOf(fileBytes);
String des = "s"+soc;
return des.getBytes();
}
每次增加的时候都new一个新的数组合适,还是直接new 最终长度的数组,直接向这个数组赋值n次合适?上述两个方法的意思:
我的意思是给数组赋值的效率哪个高。第一个方法是new 一个新的数组,然后把要赋值的数据复制到这个数组中去;
第二个方法是
没考虑过new与固定数组的区别
我也顶啦