I have a method as of below which has been running properly for a long time:
private String loadFromFile(){
RandomAccessFile inFile = null;
FileChannel inChannel = null;
StringBuilder sb = new StringBuilder();
try {
inFile = new RandomAccessFile(this.latestImageFile, "r");
inChannel = inFile.getChannel();
ByteBuffer bb = ByteBuffer.allocate(2046);
while( inChannel.read(bb) != -1){
bb.flip();
while(bb.hasRemaining()){
char c = (char) bb.get(); // read character at current position and set the pointer to current position + 1
sb.append(c);
}
bb.clear();
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (inChannel != null) try {inChannel.close(); } catch (IOException e){}
if (inFile != null ) try { inFile.close(); } catch (IOException e) {}
}
return sb.toString();
}
However, today after I have compiled and run the program on a server, below exception was logged when starting the program. It shows a flip() method is not found:
Exception in thread "main" java.lang.NoSuchMethodError: java.nio.ByteBuffer.flip()Ljava/nio/ByteBuffer;
at com.rt.stream.s.exch.OBWorker.loadFromFile(OBWorker.java:271)
at com.rt.stream.s.exch.OBWorker.initAndLoadOBs(OBWorker.java:184)
at com.rt.stream.s.exch.OBWorker.<init>(OBWorker.java:145)
at com.rt.stream.s.exch.OBWorkerMgr.initFromProperties(OBWorkerMgr.java:217)
at com.rt.stream.s.exch.OBWorkerMgr.init(OBWorkerMgr.java:132)
at com.rt.stream.s.exch.OBWorkerMgr.main(OBWorkerMgr.java:511)
Anybody has any idea on it please?
The program running environment specification is like this:
Server:
- openjdk version "1.8.0_242"
Development:
IDE: Version: 2019-09 R (4.13.0)
JDK: jdk-11.0.1
maven: apache-maven-3.3.3 (with below configuration applied)
<source>1.8</source>
<target>1.8</target>