我知道这已经被问了很多,但从来没有回答。 我definetly需要将文件写入根有没有其他解决办法。 我目前使用此代码,但它并没有显示任何在/系统/新。 我想从我的资产复制文件到/ System文件夹(与它的子目录的)
public void installFiles(View v) {
try {
Runtime.getRuntime().exec("su");
} catch (IOException e) {
mDebugView.append(e.toString());
}
copyPath("system/bin", "/system/bin/");
copyPath("system/lib", "/system/lib/");
copyPath("system/etc", "/system/etc/");
copyPath("system/etc/audio", "/system/etc/audio/");
copyPath("system/etc/soundimage", "/system/etc/soundimage/");
copyPath("system/lib/soundfx", "/system/bin/soundfx/");
}
public void copyPath(String from, String to) {
mDebugView.append("Copying path assets/" + from + " to " + to + "\n");
AssetManager assetManager = getAssets();
String[] files = null;
try {
files = assetManager.list(from);
for (String filename : files) {
mDebugView.append(filename + "... \n");
if (new File(filename).isFile()) {
mDebugView.append("Copying " + filename + "\n");
InputStream in = null;
OutputStream out = null;
in = assetManager.open(filename);
out = new FileOutputStream(to);
copyFile(in, out);
in.close();
in = null;
out.flush();
out.close();
out = null;
}
}
} catch (IOException e) {
Log.e(this.getClass().toString(), e.toString());
mDebugView.append(e.toString() + "\n");
}
}
private void copyFile(InputStream in, OutputStream out) throws IOException {
mDebugView.append("..");
byte[] buffer = new byte[1024];
int read;
while ((read = in.read(buffer)) != -1) {
out.write(buffer, 0, read);
}
}