【发布时间】:2015-07-11 11:25:08
【问题描述】:
我正在尝试从资产文件夹中的命名子文件夹复制文件,但在尝试使用该文件时出现“未找到错误”。显然它似乎没有正确复制文件。
这是我所做的,也许有人能发现我的错误
方法调用:
copyfile("/lollipop/proxy.sh");
方法:
public void copyfile(String file) {
String of = file;
File f = new File(of);
String basedir = getBaseContext().getFilesDir().getAbsolutePath();
if (!f.exists()) {
try {
InputStream in =getAssets().open(file);
FileOutputStream out =getBaseContext().openFileOutput(of, MODE_PRIVATE);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
out.close();
in.close();
Runtime.getRuntime().exec("chmod 700 " + basedir + "/" + of);
} catch (IOException e) {
Log.e(TAG, "Error reading I/0 stream", e);
}
}
}
尝试使用 proxy.sh 失败,因为该文件似乎从未被复制,但是当我删除“棒棒糖”目录时它工作正常。似乎有什么问题?天呐
【问题讨论】:
标签: android fileoutputstream android-assets