【发布时间】:2019-06-02 01:08:11
【问题描述】:
我正在设置一个函数来收集 apk 文件列表,然后在 For 循环中,我声明一个 ZipFile 密集来检查 lib 文件夹下的 ABI 目录,方法是检查是否有任何文件以 ".所以”。我能想到的唯一解决方案是使用正则表达式字符串表达式
我已经使用 \b, [A-Za-z-0-9]* 进行了几次正则表达式尝试,但我不断收到 NullPointerException。我研究了使用带有文件名的正则表达式的解决方案,但不是 ZipFile 和 ZipEntry 类的真正案例。目前,这是我目前使用正则表达式的方法。 (有时正则表达式让我头晕目眩。)
public void createAPKList() throws ZipException, IOException {
apkFileList = new File("C:/eclipse/workspace/Appium-Side-Project/APKDir/APKFiles").listFiles();
System.out.println(apkFileList[apkFileList.length-1].getPath());
apkInstallOptions = storeAndSortFiles(apkFileList, apkInstallOptions);
}
private HashMap<String, File> storeAndSortFiles(File[] fileList, HashMap<String, File> storageList) throws ZipException, IOException{
ZipFile apkDetails;
//Example of calling specific ABI
String aBI = "armeabi-v7a/";
String patternStr = "^lib/"+aBI+"[(.*)].so$";
for(File apk : fileList) {
//how to initialize ZipEntry to assign the any file that ends with ".so" ?
apkDetails = new ZipFile(apk);
ZipEntry readFolders = apkDetails.getEntry(patternStr);
System.out.println(readFolders.getName().startsWith("lib/armeabi-v7a/"));
}
return storageList;
}
当前的解决方案给出了 NullPointerException,因为 ZipEntry 值为空。我不确定错误是来自我的正则表达式还是表达式正在工作,但对于目录中存在多个“.so”的情况。是否可以在 ZipFile/ZipEntry 中使用正则表达式?
【问题讨论】: