我希望能够从 Android 设备的内部缓存移动或复制文件,并将其放入 SD 卡上的永久存储中。这是我到目前为止所拥有的:
public void onClickSaveSecret(View v){
File image = new File(getApplication().getCacheDir() + "/image.png");
File newImage = new File(Environment.getExternalStorageDirectory() + "/image.png");
Toast.makeText(this, "Image Saved", 100).show();
}
/**
* copy file from source to destination
*
* @param src source
* @param dst destination
* @throws java.io.IOException in case of any problems
*/
void copyFile(File src, File dst) throws IOException {
FileChannel inChannel = new FileInputStream(src).getChannel();
FileChannel outChannel = new FileOutputStream(dst).getChannel();
try {
inChannel.transferTo(0, inChannel.size(), outChannel);
} finally {
if (inChannel != null)
inChannel.close();
if (outChannel != null)
outChannel.close();
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)