【发布时间】:2016-06-01 12:43:19
【问题描述】:
我正在尝试将文件保存到内部存储器中,并且应该只能由我的应用程序读取。 到目前为止,我已经尝试过了。
String filesave = Environment.getExternalStorageDirectory()+""+getFilesDir()+"/.fkfk";
File f = new File(filesave);
if (!f.exists()){
f.mkdir();
}
File sd = Environment.getExternalStorageDirectory();
Log.e("files", Environment.getExternalStorageDirectory()+f.getAbsolutePath());
String path = Environment.getExternalStorageDirectory()+"/.NEWFolders/hdfc0002.jpg";
File toCopy = new File(path);
if (toCopy.exists()){
Log.e("ok","got the path");
try{
if (sd.canWrite()) {
File source= toCopy;
File destination=f;
if (source.exists()) {
FileChannel src = new FileInputStream(source).getChannel();
FileChannel dst = new FileOutputStream(destination).getChannel();
if (dst != null && source != null) {
dst.transferFrom(src, 0, src.size());
}
if (src != null) {
src.close();
}
if (dst != null) {
dst.close();
}
}else {
FileChannel src = new FileInputStream(source).getChannel();
FileChannel dst = new FileOutputStream(destination).getChannel();
if (dst != null && source != null) {
dst.transferFrom(src, 0, src.size());
}
if (src != null) {
src.close();
}
if (dst != null) {
dst.close();
}
}
}
}catch (FileNotFoundException e){
e.printStackTrace();
}catch (IOException e){
e.printStackTrace();
}
}
但是这段代码 sn-p 抛出 FileNotFound 异常。 请同样建议我。 提前致谢
【问题讨论】:
标签: android file security android-internal-storage