У меня есть следующий код, который работает без ошибок и успешно записывает выходной файл. Тем не менее, я не могу открыть выходной файл. он всегда выдает сообщение об ошибке, в котором говорится "слово найдено нечитаемым контентом"
кто-нибудь может посоветовать, если что-то не так с моим кодом?
`File inputf = new File("C:\\Appl\\CM table deployment.docx");
File outputf = new File("C:\\Appl\\CM table deployment1.docx");
RandomAccessFile infile = new RandomAccessFile(inputf, "r");
RandomAccessFile outfile = new RandomAccessFile(outputf, "rw");
FileChannel inChannel = infile.getChannel();
FileChannel outChannel = outfile.getChannel();
ByteBuffer inbuffer = ByteBuffer.allocate(1024*64);
long position = 0;
System.out.println("inChannel.size(): " + inChannel.size());
while(inChannel.read(inbuffer) > 0)
{
inbuffer.flip();
ByteBuffer outbuffer;
if(position+inbuffer.capacity()<inChannel.size())
outbuffer = ByteBuffer.allocate(1024*64);
else
outbuffer = ByteBuffer.allocate((int)(inChannel.size()-position+1));
outbuffer.put(inbuffer.get());
while (outbuffer.hasRemaining()){
outChannel.write(outbuffer, position);
if(position+inbuffer.capacity()<inChannel.size()){
position = position + inbuffer.capacity();
System.out.println("next position : "+ position);
}
else{
position = position+1;
System.out.println("next position : "+ position);
}
}
outbuffer.clear();
inbuffer.clear(); // do something with the data and clear/compact it.
}
inChannel.close();
outChannel.close();
infile.close();
outfile.close();
`