众所周知,安卓某些资源目录,RAW目录以及ASSETS目录下的文件都能轻易读取,但是工程根目录下的文件android确没有提供方法读取,只能自己想办法,曲线救国了android应用的后缀名称为.apk其实就是一个压缩文件,可以用解压缩工具查看里面的文件信息,那我想也可以通过读取压缩包文件的方式读取工程根目录下的文件的内容,android也提供了读取压缩文件信息的接口。那么就需要找到这个压缩包的存在,还好android提供了一个方法可以读取到apk的信息context.getPackageCodePath(),下面是详细代码:
private static File findFile(Context context) {
String str3 = context.getPackageCodePath();
try {
ZipInputStream zipInput=new ZipInputStream(new FileInputStream(str3));
ZipEntry currentZipEntry = null;
while ((currentZipEntry=zipInput.getNextEntry())!=null) {
String name = currentZipEntry.getName();
if (!currentZipEntry.isDirectory()) {
Log.d("zengnengxin", name + "is a normal file");
if( name.equalsIgnoreCase("And