java - 如何更新 Alfresco 中的文件内容?

标签 java alfresco

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

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

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 是追加字符串。

关于java - 如何更新 Alfresco 中的文件内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7752351/

相关文章:

java - JSON 对象无法获取字符串

android - webview - access-control-allow-origin 不允许来源(使用 cordova 将 Angular 转换为移动)

java.sql.Date 不打印正确的日期

java - 如何在 Spring REST 文档中切换语言环境?

java - 下载源代码后,为什么我会在堆栈跟踪中看到未知源?

tomcat - 在现有 Tomcat 上安装 Alfresco War

javascript - 如何使用 json.ftl 获取 Alfresco 中关联对象的属性

database - 无法启动 Alfresco 3.4.4(启动 postgresql 时出错)

java - Alfresco 内容存储库 API 的副作用?

java - 将字符串反序列化为对象