在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);
}
}
您可以尝试使用完整的句子编写吗?我无法理解问题是什么。 –
这不应该被关闭 - 对那些熟悉android的人来说,这是一个真正的问题,正如接受的答案所指出的那样,这是一个可以回答的问题。 –