[英]android 1.5, programmatically copy songs form /sdcard/songs to /sdcard/backup
我正在使用eclipse模拟器,我想以编程方式将一些mp3从/ sdcard / songs复制到/ sdcard / backup ,有什么办法吗? 非常感谢任何帮助和代码段! 谢谢! :)
您可以尝试以下方法:
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) {}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.