2013-05-21 69 views
0

出于某种原因,我需要加入一些与我的apk文件的defaut文件,但我需要写入SD卡,因为我的应用程序试图读取我需要第一次存储的SD卡我的SD卡的默认文件在APK中加入文件将它们存储在SD卡中

如何做到这一点,我不能粘贴我的数据在我的根文件夹android拒绝它,如果我把它粘贴在一个可绘制的文件夹它似乎确定编译,但我仍然duno如何获得内容和我的SD卡上写

我看到很多政党成员TU得到从SD卡的可绘制,但我wan't相反,我会从默认的文件我已经加入写SD卡上的文件到APK

有什么想法?我没有代码,因为我没有任何提示可以做到这一点

+1

您可以尝试使用完整的句子编写吗?我无法理解问题是什么。 –

+2

这不应该被关闭 - 对那些熟悉android的人来说,这是一个真正的问题,正如接受的答案所指出的那样,这是一个可以回答的问题。 –

回答

0

在Eclipse中压缩文件并将压缩文件(将其命名为my_raw_files.zip)存储到文件夹res/raw中,并将其与您的应用程序。然后,您可以在第一次启动应用程序时将其复制到外部存储设备(“sdcard”):

private static final File USER_DIR = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator 
     + "myfolder"); 
... 
boolean dirCreated = USER_DIR.mkdirs(); 
if (dirCreated) 
{ 
    FilesUtil.unzipFiles(this.getResources().openRawResource(R.raw.my_raw_files), 
        USER_DIR.getAbsolutePath()); 
} 
... 
static public void unzipFiles(InputStream zipIS, String outputPath) 
{ 
    try 
    { 
     // unzip files into existing folder structure 
     ZipInputStream zin = new ZipInputStream(zipIS); 
     try 
     { 
      ZipEntry ze; 
      while ((ze = zin.getNextEntry()) != null) 
      { 
       if (!ze.isDirectory()) 
       { 
        Log.d(TAG, "unzip " + ze.getName()); 

        ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
        byte[] buffer = new byte[1024]; 
        int count; 
        FileOutputStream fout = new FileOutputStream(outputPath + File.separator + ze.getName()); 
        while ((count = zin.read(buffer)) != -1) 
        { 
         baos.write(buffer, 0, count); 
         byte[] bytes = baos.toByteArray(); 
         fout.write(bytes); 
         baos.reset(); 
        } 
        fout.close(); 
       } 
      } 
     } finally 
     { 
      zin.close(); 
     } 

    } catch (Exception e) 
    { 
     Log.e(TAG, "unzip", e); 
    } 

}  
相关问题