获得在Android的源代码包的子文件夹名和文件名列表 [英] Getting list of subfolders name and files name in android source package
问题描述
我正在开发用于存储SQL文件更新SQLite数据库Android应用程序。并且SQL脚本将运行在用户按下特定的按钮。这就是我把我的SQL文件
I'm developing an android application that store sql files to update the sqlite database. And that sql script will run when user push certain button. This is where i put my sql files
到目前为止,我一直在使用这种解决方案来运行我的脚本: 首先,我映射更新资源作为update.xml
So far i've been using this solution to run my script: First, mapping my update to resource as update.xml
<resources>
<string name="update_list">
v2_9_11
</string>
<string-array name="v2_9_11">
<item>1_AlterTable_wapactivity</item>
</string-array>
</resources>
和获得使用这种方法的文件中的SQL脚本:
And get the sql script inside the file with this method :
private void runScript(String version_name){
try{
String[] sql_list = mGap.getResources().getStringArray(getArrayIdentifier(mGap, version_name));
for (String sql : sql_list) {
InputStream in = getClass().getResourceAsStream("/com/ods/scm/script/update/"+version_name+"/"+sql+".sql");
Reader fr = new InputStreamReader(in, "utf-8");
BufferedReader br = new BufferedReader(fr);
String s="";
String baris;
while((baris=br.readLine())!=null){
s+=baris;
}
mDbHelper.executeStatement(s);
}
insertUpdate(version_name);
}
catch(Exception e){
System.out.println(e.getMessage());
}
}
我从update.xml字符串VERSION_NAME和String [] sql_list文件名。 问题是,我想VERSION_NAME(在这种情况下v2_9_11从文件夹中更新子文件夹名称)和SQL文件名(在这种情况下1_AlterTable_wapactivity.sql),而它update.xml映射。可以ayone帮帮我吗?
I get the String version_name and String[ ] sql_list file name from update.xml. The problem is, i want to get version_name ( in this case v2_9_11 as subfolder name from folder update ) and sql file name ( in this case 1_AlterTable_wapactivity.sql ) without mapping it in update.xml. Can ayone help me?
修改
或者,任何人都可以直接我如何自动映射到update.xml当构建应用程序?
EDIT
Or can anyone direct me how to automatically mapping it to update.xml when build the application?
推荐答案
抱歉的是,我刚才把它放在赏金,但我能解决这个问题由我自己在很短的时间我把它放在赏金后。总之,我的解决办法是打开的apk文件在Android设备内(数据/应用/ .... APK)作为一个zip流。然后列出所有以 COM / ODS / SCM /脚本/更新
文件。在这里,我的方法来获取开始使用它的所有文件:
Sorry all, i just now put it in bounty but i'm able to resolve it by myself by the short time after i put it in bounty. Anyway, my solution is to open the apk file that inside the android device (data/app/....apk) as a zip stream. Then list all the file that start with com/ods/scm/script/update
. Here my method to get all file that start with it :
public ArrayList openApk(String filePath){
ArrayList<String> list = new ArrayList<String>();
FileInputStream fis = null;
ZipInputStream zipIs = null;
ZipEntry zEntry = null;
try {
fis = new FileInputStream(filePath);
zipIs = new ZipInputStream(new BufferedInputStream(fis));
while((zEntry = zipIs.getNextEntry()) != null){
if(zEntry.getName().startsWith("com/ods/scm/script/update/"))
list.add(zEntry.getName());
}
zipIs.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return list;
}
这篇关于获得在Android的源代码包的子文件夹名和文件名列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!