我的应用程序使用Java类RandomAccessFile通过实现SeekableByteChannel接口在SD卡上随机读写字节。现在我需要使用新的Lollipop API重写它以适配Android 5.0。
我已经找到了唯一的方法来进行读取:
InputStream inputStream = getContentResolver().openInputStream(uri);
并写下:
ParcelFileDescriptor pfd = getActivity().getContentResolver().openFileDescriptor(uri, "w");
FileOutputStream fileOutputStream = new FileOutputStream(pfd.getFileDescriptor());
从/向新API的文件中读取/写入。
我希望能够在某个随机位置设置通道并读/写字节到该位置。在新的SDK 21中是否有可能做到这一点?新的SDK是否意味着获得通道的这种方式:
FieInputChannel fieInputChannel = fileInputStream.getChannel();
FieOutputChannel fieOutputChannel = fileOutputStream.getChannel();
还是其他方法?