首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Alfresco中更新文件的内容?

如何在Alfresco中更新文件的内容?
EN

Stack Overflow用户
提问于 2011-10-13 17:54:42
回答 1查看 2.8K关注 0票数 0

我的基于java的webscript将存储库中的文件复制到临时文件夹中,并根据需要对其进行编辑。在其工作期间,会生成新内容,并且必须将其写入到创建的临时文件中。

但有一个问题:下面的第一个或第二个代码不会更新文件的内容。

代码语言:javascript
复制
ContentWriter contentWriter = this.contentService.getWriter(tempFile,
                               ContentModel.PROP_CONTENT, true);
contentWriter.putContent(content);

第二个是:

代码语言:javascript
复制
`
WritableByteChannel byteChannel = contentWriter.getWritableChannel();
ByteBuffer buffer = ByteBuffer.wrap(content.getBytes());
byteChannel.write(buffer);
byteChannel.close();
`

如何更新文件内容?

EN

回答 1

Stack Overflow用户

发布于 2011-10-13 18:02:23

这对我来说很有效:

代码语言:javascript
复制
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是附加字符串。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7752351

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档