Java内核32。读取文件错误(字节缓冲无法转换为字节[])
我试图用以下代码阅读Java中的NamedPipe:
ByteBuffer buffer = ByteBuffer.allocate(4*1024);
IntByReference bytesRead = new IntByReference(buffer.capacity());
int lastError = 0;
if (kernel32.PeekNamedPipe(pipeHandle, buffer, buffer.capacity(), bytesRead, null, null))
while ( !(kernel32.ReadFile(pipeHandle, /*(!)ERROR HERE==>*/buffer, buffer.capacity(), bytesRead, overlapped)) || (lastError=kernel32.GetLastError()) == Kernel32.ERROR_MORE_DATA){
if (lastError == Kernel32.ERROR_PIPE_NOT_CONNECTED || overlapped.Internal.intValue() != WinNT.ERROR_IO_PENDING)
break;
}
但它失败了,出现了以下错误:incompatible types: ByteBuffer cannot be converted to byte[]
。我试图用byte[] b = new byte[buffer.remaining()];
中的b
替换buffer
,但程序开始出错。任何关于如何修复错误的想法都是受欢迎的。谢谢
# 1 楼答案
通过以下方式解决了问题:
再次检查了程序的返回
谢谢大家