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

android中实现内存中数据保存到sdcard

2018年02月10日 ⁄ 综合 ⁄ 共 559字 ⁄ 字号 评论关闭

    public static void writeToSdCard(String s) {
        try {
            File dst = new File("/sdcard/test_sensor/" + mName + ".txt");
            File parent = dst.getParentFile();
            if(!parent.exists()) {

                parent.mkdirs(); 

            }

            FileOutputStream outStream = new FileOutputStream(dst, true);
            OutputStreamWriter writer = new OutputStreamWriter(outStream, "gb2312");
            writer.write(s);
            writer.write("\n");
            writer.flush();
            writer.close();// 记得关闭

            outStream.close();
        } catch (Exception e) {
            Log.i("test result", "file write error");
            e.printStackTrace();
        }
    }

抱歉!评论已关闭.