现在的位置: 首页 > 综合 > 正文

android 随手记 – savefile

2018年02月17日 ⁄ 综合 ⁄ 共 981字 ⁄ 字号 评论关闭

private static void savefile(InputStream is, String filename) {
        int BUFFER_SIZE = 1024;
        byte[] buf = new byte[BUFFER_SIZE];
        int size = 0;

        filepath = filepath + filename + ".txt";
        filename=null;
        File file = new File(filepath);
        filepath=null;
        if (!file.exists()) {
            try {
                file.createNewFile();
            } catch (IOException e) {

                e.printStackTrace();
            }
        }
        FileOutputStream out = null;
        BufferedInputStream bis = null;
        try {
            bis = new BufferedInputStream(is);

            out = new FileOutputStream(file);
            int i = 0;
            // while ((i = is.read()) != -1) {
            // out.write(i);
            // }

            while ((size = bis.read(buf)) != -1)
                out.write(buf, 0, size);

        } catch (Exception e) {

            e.printStackTrace();
        } finally {
            
            try {
                out.close();
                bis.close();
                is.close();
                
            } catch (Exception e) {
                
                e.printStackTrace();
            }
        }

    }

抱歉!评论已关闭.