如何将文件从设备的内部存储器移动到 Android中的外部存储器?请提供代码示例.我的代码如下 private void moveFile(File file, File dir) throws IOException { File newFile = new File(dir, file.getName()); FileCh
private void moveFile(File file, File dir) throws IOException { File newFile = new File(dir, file.getName()); FileChannel outputChannel = null; FileChannel inputChannel = null; try { outputChannel = new FileOutputStream(newFile).getChannel(); inputChannel = new FileInputStream(file).getChannel(); inputChannel.transferTo(0, inputChannel.size(), outputChannel); inputChannel.close(); file.delete(); } finally { if (inputChannel != null) inputChannel.close(); if (outputChannel != null) outputChannel.close(); } }从路径中删除尾部斜杠.因为example.png不是目录,所以不需要它.实际上不要硬编码SD卡的路径,因为它可能因设备而异.尝试使用Environment.getExternalStorageDirectory()获取sdcard的路径,然后在最后添加任何尾随路径.
请看一下documentation.