众所周知,安卓某些资源目录,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("AndroidManifest.xml")){
File file = new File(context.getFilesDir() + File.separator + name);
file.createNewFile();
// get the output stream of the file
FileOutputStream out = new FileOutputStream(file);
int ch;
byte[] buffer = new byte[1024];
//read (ch) bytes into buffer
while ((ch = zipInput.read(buffer)) != -1){
// write (ch) byte from buffer at the position 0
out.write(buffer, 0, ch);
out.flush();
}
out.close();
return file;
}
}
}
zipInput.close();
} catch (Exception e) {
// TODO: handle exception
}
return null;
}