Storage Access Framework(Android Lollipop API 21)是否支持文件截断操作?

时间:2016-11-17 16:41:07

标签: android android-5.0-lollipop truncate storage-access-framework

我需要在可移动SD卡上截断文件。由于存储访问框架(SAF)限制,我无法直接在文件上调用 truncate(someSize)并被强制使用:

newx = x(:,1) + x(:,2)(nonzeros)
     = [1 2 3 4 5 1 2 3];

结果我有一个例外:

    ParcelFileDescriptor pfd = getContentResolver().openFileDescriptor(documentFile.getUri(), "rw");
    FileOutputStream fos = new FileOutputStream(pfd.getFileDescriptor());
    fileChannel = fos.getChannel();
    fileChannel.truncate(someSize);

如果我在 rw 模式下打开文件描述符,为什么上面的频道不可写?还有另一种方法在Lollipop上截断SAF下的文件!?

0 个答案:

没有答案