메모리 매핑 된 쓰기를 수행하기 위해 fileChannel을 만들고 있습니다. 이 fileChannel의 크기는 100 바이트입니다. 나는 그것에 80 바이트만을 쓴다. 그래서 나중에 그 파일을 읽을 때, and에 5 "0"이 추가됩니다. 크기를 설정하거나 크기를 파일에 기록 할 수있는 방법이 있습니까?내용보다 큰 Java FileChannel
감사합니다.
public FileChannel create(String randomFile){
// create file output stream
RandomAccessFile raf;
FileChannel fc = null;
try {
raf = new RandomAccessFile(randomFile, "rw");
fc = raf.getChannel();
System.out.println("fc.size() "+ fc.size());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return fc;
}
왜'FileChannel.open()'을 사용하지 않으시겠습니까? – fge
FileChannel을 사용하여 MappedByteBuffer.mbb = fc.map (MapMode.READ_WRITE, position, bufferSize);을 만든 다음 해당 버퍼에 쓰기 –