文件读写

来源:互联网 发布:什么是云计算服务器 编辑:程序博客网 时间:2024/06/12 20:14
 public static void initHoliday(Context context) {        String strPath = "/data/data/" + context.getPackageName() + "/shared_prefs/";        String strFileName = "holiday.xml";        if (!(new File(strPath + strFileName)).exists()) {            File f = new File(strPath);            if (!f.exists()) {                f.mkdir();            }            try {                InputStream is = context.getAssets().open(strFileName);                OutputStream os = new FileOutputStream(strPath + strFileName);                byte[] buffer = new byte[1024 * 64];                int length;                while ((length = is.read(buffer)) > 0) {                    os.write(buffer, 0, length);                }                os.flush();                os.close();                is.close();            } catch (Exception e) {                e.printStackTrace();            }        }    }
0 0
原创粉丝点击