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

    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();
        }
    }

你可能感兴趣的:(android中实现内存中数据保存到sdcard)