大家好老家伙新手在这里... 我定义了一个字符串=> final static String Blank = ""; 和一个字节数组 static byte[] LU62_Partner = new byte[8] ;
在我的逻辑中,我想用空白初始化 byte[] 数组
// Prep LU6.2 Session
for ( ndx=0 ; ndx < 8 ; ++ndx)
{
LU62_Partner[ndx] = Blank.getBytes() ; // initialize the the LU6.2 partner name byte array w/blanks
}
LU62_Partner = APPC_Partner.getBytes() ; // convert string array to byte array
// if the appc-partner name < 8 bytes, rightmost bytes
// will be padded with blanks
但是在编译时我得到以下错误 src\LU62XnsCvr.java:199: 不兼容的类型 发现:字节[] 要求:字节 LU62_Partner[ndx] = Blank.getBytes() ;
我再次感到困惑...我的印象是方法 getBytes() 会将字符串转换为字节。 再次感谢
家伙
最佳答案
getBytes() 返回一个数组,因此您试图将一个字节数组塞进一个字节
使用
Arrays.fill(LU62_Partner, (byte)' ');
关于java - 需要用 ascii 空白初始化 byte[] 数组(即 0x20 或 ""),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5785517/