您的位置:首页 > 其它

解决Assert目录下无法拷贝超大文件到SD卡的问题

2010-05-11 21:16 399 查看
Assert 目录文件拷贝时候, Android 有个规定就是文件大小不能操作1M, 不然会抛文件太大的错误. 解决办法如下. 将文件拷贝到类文件下:

代码示意如下:
private static boolean copyFile(Context ctx, String filename, String des) {
InputStream instream = null;
try {
if (filename.contains("TUIRes.ndt")) { //这个文件超过1M
instream = XmlFile.class.getResourceAsStream("TUIRes.ndt");
} else if (filename.contains("TUpdateRes.ndt")) {
instream = XmlFile.class.getResourceAsStream("TUpdateRes.ndt");
} else {
instream = ctx.getAssets().open(filename);
}

copyFile(des, instream);
return true;
} catch (Exception e) {
return false;
}
}

private static void copyFile(String fileToPath, InputStream in)
throws Exception {
OutputStream out = null;
try {

out = new FileOutputStream(fileToPath);
byte[] buffer = new byte[1024];
while (true) {
int ins = in.read(buffer);
if (ins == -1) {
break;
}

out.write(buffer, 0, ins);
}
} finally {
if (in != null) {
in.close();
}
if (out != null) {
out.flush();
out.close();
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐