- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在将值写入文件。
值写正确。在另一个应用程序中,我可以毫无异常(exception)地读取文件。
但是在我的新应用程序中,尝试读取文件时收到了Bufferunderflowexception
。
我花了几天的时间来解决这个问题,但我只是不知道如何解决。
也做了很多研究。bufferunderflowexception
指的是:
Double X1 = mappedByteBufferOut.getDouble(); //8 byte (double)
@Override
public void paintComponent(Graphics g) {
RandomAccessFile randomAccessFile = null;
MappedByteBuffer mappedByteBufferOut = null;
FileChannel fileChannel = null;
try {
super.paintComponent(g);
File file = new File("/home/user/Desktop/File");
randomAccessFile = new RandomAccessFile(file, "r");
fileChannel = randomAccessFile.getChannel();
mappedByteBufferOut = fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, randomAccessFile.length());
while (mappedByteBufferOut.hasRemaining()) {
Double X1 = mappedByteBufferOut.getDouble(); //8 byte (double)
Double Y1 = mappedByteBufferOut.getDouble();
Double X2 = mappedByteBufferOut.getDouble();
Double Y2 = mappedByteBufferOut.getDouble();
int colorRGB = mappedByteBufferOut.getInt(); //4 byte (int)
Color c = new Color(colorRGB);
Edge edge = new Edge(X1, Y1, X2, Y2, c);
listEdges.add(edge);
}
repaint();
for (Edge ed : listEdges) {
g.setColor(ed.color);
ed = KochFrame.edgeAfterZoomAndDrag(ed);
g.drawLine((int) ed.X1, (int) ed.Y1, (int) ed.X2, (int) ed.Y2);
}
}
catch (IOException ex)
{
System.out.println(ex.getMessage());
}
finally
{
try
{
mappedByteBufferOut.force();
fileChannel.close();
randomAccessFile.close();
listEdges.clear();
} catch (IOException ex)
{
System.out.println(ex.getMessage());
}
}
}
最佳答案
从java.nio.ByteBuffer的docs中:
Throws: BufferUnderflowException - If there are fewer than eight bytes remaining in this buffer
while (mappedByteBufferOut.remaining() >= 36) {//36 = 4 * 8(double) + 1 * 4(int)
关于java - Java的BufferunderflowException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20644505/
我正在使用这个函数将 bytearray 转换为 int。 public static int byteArrayToInt(byte[] b) { ByteBuffer bb = ByteB
处理 4MB 日志文件时遇到了与this guy类似的问题。实际上,我正在同时处理多个文件,但是由于我不断收到此异常,因此我决定仅对单个文件进行测试: val temp = Source.fromFi
这段代码有什么问题? : ByteBuffer byteBuffer = ByteBuffer.allocate(4); FileChannel channel = cacheFile.getChan
我从以下代码中获取 BufferUnderflowException。 int length = mBuf.remaining(); char[] charBuff = new char[length
我有一个非常简单的 Java EE 应用程序,其中包含一些使用 JMS 进行通信的 bean。当我尝试部署和调试我的应用程序时,我得到了这个 Informazioni: visiting unvi
我正在获取 String 的 ByteBuffer,例如100如下 ByteBuffer data = IntegerSerializer.get().toByteBuffer(Integer.par
我对 kaitai-struct 和 java 还很陌生。我已将 .ksy 文件解析为目标语言 java,但在 eclipse ide 中编译后,我得到“java.nio.BufferUnderflo
我正在尝试编写一个程序来使用 Java nio 通过数据报 channel 发送和接收序列化对象,但在尝试从 ObjectInputStream 读取我的对象时收到 BufferUnderFlow 异
我需要将 bytearray 转换为 double。我正在使用 double dvalue = ByteBuffer.wrap(value).getDouble(); 但是在运行时我得到 Buffer
我正在尝试做一些 scripting in Scala , 处理一些日志文件: scala> import io.Source import io.Source scala> import java.
在消费者上获取此 kafka 异常: org.apache.kafka.common.protocol.types.SchemaException: Error reading field 'corr
非常小的一段代码,但我对这种行为感到非常惊讶。我有一个字节数组中的 14 字节 key 。我将这个字节数组放入 ByteBuffer,然后执行 getLong 给我一个 BufferUnderflow
9.0 客户端使用来自远程系统上运行的两个代理的消息。我的生产者工作正常并且能够向代理发送消息,但我的消费者无法使用这些消息。消费者和生产者正在我的本地系统上运行两个经纪人都在 aws 上。 每当我尝
我是一名优秀的程序员,十分优秀!