public FileProcessor(String filenameIn, String fileModeIn){
try {
randomaccessfile = new RandomAccessFile(filenameIn, fileModeIn);
fileChannel = randomaccessfile.getChannel();
buffer = fileChannel.map(FileChannel.MapMode.READ_WRITE, 0, fileChannel.size());
} catch (FileNotFoundException e) {
System.err.println("Error while creating a File");
e.printStackTrace();
System.exit(1);
} catch (IOException e) {
System.err.println("Error while creating MappedByteBuffer");
e.printStackTrace();
System.exit(1);
}
異常線程 「main」 java.nio.channels.NonWritableChannelException 在sun.nio.ch.FileChannelImpl.map(FileChannelImpl.java:880)JAVA - 非可寫通道異常
獲取NonwritableChannelException爲上面的代碼。請幫忙。謝謝。!!
什麼是你的fileModeIn? – developer
我得到一個文件模式作爲輸入,但默認設置爲READ_WRITE – ShreyasMN