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

前端 未结 2 539
小蘑菇
小蘑菇 2020-12-20 03:56

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

相关标签:
2条回答
  • 2020-12-20 04:12

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

    0 讨论(0)
  • 2020-12-20 04:12

    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;
    }
    
    0 讨论(0)
提交回复
热议问题