您的位置:首页 > 移动开发

Android 往自己的APP加入文件

2011-07-19 12:06 357 查看
首先把自己需要安装的文件放在工程里的assert目录下。然后代码如下“;
/** @author  xuxin
*down load tht simotun file
*/
private void loadSimotunFile(){
if(!isFileExist(mexeFilePath))
try {
InputStream in=getAssets().open("simotun") ;
saveToFile(mexeFilePath,in);
} catch (IOException e1) {
e1.printStackTrace();
}
}


/** @author  xuxin
* get inputStream,and write it to a new file
*/
public void saveToFile(String fileName, InputStream in) throws IOException {
FileOutputStream fos = null;
BufferedInputStream bis = null;
int BUFFER_SIZE = 1024;
byte[] buf = new byte[BUFFER_SIZE];
int size = 0;
bis = new BufferedInputStream(in);
fos = new FileOutputStream(fileName);
while ( (size = bis.read(buf)) != -1)
fos.write(buf, 0, size);
fos.close();
bis.close();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: