我试图将文件从资源文件夹命名的子文件夹复制,但尝试使用该文件时遇到了“未找到错误”。显然它似乎没有复制该文件的权利。文件中的资源文件夹
这里是我做了什么,也许有人能发现我的错误
方法调用:
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因为该文件似乎从来没有复制,但当我删除“棒棒糖”目录,它工作正常。什么似乎不对? TNX
,就可以得到任何更好的方法来复制该文件在正常吗? – CodeZero
@CodeZero:这取决于你在本地文件系统上想要什么。如果你想在本地文件系统,你有'资产/'相同的目录结构,使用'getFilesDir()''而不是openFileOutput()'。如果你只是简单地拷贝这个文件并且不需要'lollipop /'作为本地文件系统的一个目录,那么调用''''''''''''''来获取文件名,然后传递'getName() ''openFileOutput()'的结果。 – CommonsWare
花了2天时间,没有你的解决方案。 – CodeZero