亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

獲取 asset 文件夾中文件的內容 URI

獲取 asset 文件夾中文件的內容 URI

弒天下 2023-07-28 16:57:15
我的 asset 文件夾中有一個 zip 文件,我想要它的內容 uri。我可以使用以下方法獲取文件 uri:final Uri uri = Uri.fromFile(new File("file:///android_asset/xyz.zip"));對于內容 uri 我嘗試使用:final Uri uri = Uri.parse("content://com.example.myproject/xyz.zip");但它不起作用?
查看完整描述

1 回答

?
慕勒3428872

TA貢獻1848條經驗 獲得超6個贊

試試這個代碼


InputStream inputStream = am.open("myfoldername/myfilename");

File file = createFileFromInputStream(inputStream);

final Uri uri = Uri.fromFile(file);


private File createFileFromInputStream(InputStream inputStream) {

try{

  File f = new File(my_file_name);

  OutputStream outputStream = new FileOutputStream(f);

  byte buffer[] = new byte[1024];

  int length = 0;


  while((length=inputStream.read(buffer)) > 0) {

    outputStream.write(buffer,0,length);

  }


  outputStream.close();

  inputStream.close();


  return f;

 }catch (IOException e) {

     //Logging exception

 }


return null;

}


查看完整回答
反對 回復 2023-07-28
  • 1 回答
  • 0 關注
  • 297 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號