Android:从现有 URI 保存文件

标签 android android-intent media

如何从现有的 URI 中保存媒体文件(例如 .mp3),我是从隐式 Intent 中获取的?

最佳答案

用这个方法,有效

void savefile(URI sourceuri)
{
    String sourceFilename= sourceuri.getPath();
    String destinationFilename = android.os.Environment.getExternalStorageDirectory().getPath()+File.separatorChar+"abc.mp3";

    BufferedInputStream bis = null;
    BufferedOutputStream bos = null;

    try {
      bis = new BufferedInputStream(new FileInputStream(sourceFilename));
      bos = new BufferedOutputStream(new FileOutputStream(destinationFilename, false));
      byte[] buf = new byte[1024];
      bis.read(buf);
      do {
        bos.write(buf);
      } while(bis.read(buf) != -1);
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      try {
        if (bis != null) bis.close();
        if (bos != null) bos.close();
      } catch (IOException e) {
            e.printStackTrace();
      }
    }
}

关于Android:从现有 URI 保存文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13133579/

相关文章:

flash - Azure 媒体服务和 Flash 视频播放器

css - 打印 CSS : fit in one page

android - intent.setFlags(805306368) 在 android 中是什么意思

android - gradle 构建时无法应用插件 [id 'com.chaquo.python']

java - 检测到设备正在关闭?

android - 房间库不接受字节数组

java - 从 IntentService 传递数据

ANDROID:按下后退按钮后的 Activity 状态

css - 设置浏览器的媒体类型

android - 右抽屉中的抽屉切换