Android 往自己的APP加入文件

来源:互联网 发布:linux命令查看进程 编辑:程序博客网 时间:2024/05/16 02:09

首先把自己需要安装的文件放在工程里的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();             } 

 

原创粉丝点击