#Assets文件 copy
package com.example.writefile;
import android.content.Context;
import android.util.Log;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
public class assetsHelper {
public boolean copyFile(Context context, String assetsPath, String savePath) {
// assetsPath 为空时即 /assets
try{
InputStream is = context.getAssets().open(assetsPath);
FileOutputStream fos = new FileOutputStream(new File(savePath));
byte[] buffer = new byte[1024];
int byteCount = 0;
while ((byteCount = is.read(buffer)) != -1) {// 循环从输入流读取
// buffer字节
fos.write(buffer, 0, byteCount);// 将读取的输入流写入到输出流
}
fos.flush();// 刷新缓冲区
is.close();
fos.close();
}catch (Exception e){
return false;
}
return true;
}
}
new assetsHelper().copyFile(this,"runtest","/data/data/"+getPackageName()+"/runcx");