【发布时间】:2015-03-25 17:08:55
【问题描述】:
我有一个下面的 sn-p 可以在 Grovy 中完美运行,现在正在尝试将其转换为 java,但我得到了
protected String[] extractText(byte[] fileData) {
//Remove the BOM if present
if (fileData.length > 3 && fileData[0..2] == [0xEF, 0xBB, 0xBF] as byte[])
{
fileData = fileData[3..fileData.length-1]
}
// method implemaentation
}
我尝试将其更改如下,但出现 Incompatible operand types byte and byte[] 编译器错误
byte[] array= { (byte)0xEF, (byte)0xBB, (byte)0xBF };
fileData.length > 3 && fileData[0..2] == array
我从未使用过字节数组,有人可以帮我解决这个问题吗?
【问题讨论】:
-
您的
array变量已正确初始化。现在尝试将其与fileData进行比较。请看:how to compare the Java Byte[] array?