簡體   English   中英

使用存儲訪問框架

[英]using Storage Access Framework

如果您寫入一些數據,它將很好地工作。 但是,如果您寫入大量數據(將運行很長時間),它將失敗並顯示以下內容: java.io.IOException: write failed: EBADF (Bad file number)

這是代碼:

writeLargeDataToStream(new FileOutputStream(getContentResolver()
        .openFileDescriptor(data.getData(), "w").getFileDescriptor()));

看來您需要通過將其放入如下本地字段中來使ParcelFileDescriptor保持不被垃圾回收:

private ParcelFileDescriptor descriptor;

並執行以下操作:

descriptor = getContentResolver().openFileDescriptor(data.getData(), "w");
writeLargeDataToStream(new FileOutputStream(descriptor.getFileDescriptor()));

使用完之后,請使用以下命令讓垃圾收集器知道它是可收集的:

descriptor = null;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM