0
내 자바 백업 웹 스크립트는 저장소의 파일을 임시 폴더에 복사하고 내 필요에 맞게 편집합니다. 작업하는 동안 새 내용이 생성되며 작성된 임시 파일에 기록해야합니다.Alfresco에서 파일의 내용을 업데이트하는 방법은 무엇입니까?
그러나 문제가 있습니다. 아래 첫 번째 코드와 두 번째 코드는 파일 내용을 업데이트하지 않습니다.
ContentWriter contentWriter = this.contentService.getWriter(tempFile,
ContentModel.PROP_CONTENT, true);
contentWriter.putContent(content);
둘째 :
`
WritableByteChannel byteChannel = contentWriter.getWritableChannel();
ByteBuffer buffer = ByteBuffer.wrap(content.getBytes());
byteChannel.write(buffer);
byteChannel.close();
`
어떻게 파일의 내용을 업데이트 할?
ContentWriter contentWriter = contentService.getWriter(noderef, ContentModel.PROP_CONTENT, true);
contentWriter.setMimetype("text/csv");
FileChannel fileChannel = contentWriter.getFileChannel(false);
ByteBuffer bf = ByteBuffer.wrap(logLine.getBytes());
try {
fileChannel.position(contentWriter.getSize());
fileChannel.write(bf);
fileChannel.force(false);
fileChannel.close();
} catch (IOException e){
e.printStackTrace();
}
내가 기존 파일에 한 줄을 추가, 그래서 logLine은 첨부 된 문자열입니다 :
임시 파일의 전체 내용을 바꾸고 싶습니다. 코드가 작동하지 않습니다. – Alexey
안녕하세요. 모든 것을 바꾸려면 다음 행을 사용하지 마십시오. fileChannel.position (contentWriter.getSize()); 그러면 기본적으로 0이 시작 위치로 사용됩니다. –
작동하지 않습니다. 그 줄을 주석하고 0으로 설정하려고했습니다 : fileChannel.position (0). Alfresco Web Client (/ alfresco)는 파일이 수정 (날짜 변경) 되었으나 내용이 잘못되었음을 보여줍니다. – Alexey