java - 需要用 ascii 空白初始化 byte[] 数组(即 0x20 或 "")

标签 java android

大家好老家伙新手在这里... 我定义了一个字符串=> 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/

相关文章:

java - Java 是否有默认的复制构造函数(如 C++)?

java - Resteasy(多部分/表单数据): how to read multi value field values to List?

android - 使用 holoeverywhere 库时,Holo 主题不适用于对话框

java - 对于实现 Iterable 的类,Android 上下文不可序列化的困境

java - 我如何在 Android 中使用 JUnit 测试模型?

android - JSON 响应与有限数据的比较

java - 确定 char 值是否在字符范围内

java - 如果全部为空,则从 txt 中删除一行

Java 缓存和 HashMap

android - 为什么我的通知在从异步后台服务回调创建时没有显示?