Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
997 views
in Technique[技术] by (71.8m points)

xml - Getting list of subfolders name and files name in android source package

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

Where i put my sql files

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>

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());
        }
    }

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?

EDIT
Or can anyone direct me how to automatically mapping it to update.xml when build the application?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I suggest you put the .sql file in assets folder. By doing that, you are free to manipulate your file with File IO API.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...