我正在使用eclipse模拟器,我想以编程方式将一些mp3从 / sdcard / songs 复制到 / sdcard / backup ,有没有办法这样做? 任何帮助和代码片段非常感谢! 谢谢! :)
答案 0 :(得分:6)
你可以试试这个:
try {
File sd = Environment.getExternalStorageDirectory();
if (sd.canWrite()) {
String sourcePath= "/path/to/source/file.mp3";
String destinationPath= "/path/to/destination/file.mp3";
File source= new File(sd, sourcePath);
File destination= new File(sd, destinationPath);
if (source.exists()) {
FileChannel src = new FileInputStream(source).getChannel();
FileChannel dst = new FileOutputStream(destination).getChannel();
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
}
} catch (Exception e) {}