json解析并存放到sd卡文件中


/**用这个方法需要加权限
 * 往SDCard写入数据权限
 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
 */

if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
    //存放的路径
   String path =  Environment.getExternalStorageDirectory().getPath()+ File.separator+"json.text";
   File file = new File(path);
   //文件存在就删除
    if(file.exists()){
        file.delete();
    }

    try {
        file.createNewFile();//创建文件
        PrintStream ps = new PrintStream(file);//向文件中写信息
        ps.print(str);//str是解析出来的对象
        ps.flush();
        ps.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}


特别简单的

FileOutputStream open = new FileOutputStream("wenjianming.txt",MODE_PRIVATE);
open.write(list.toString().getBytes());
open.close();
//路径
data/data/包名/文件夹:files/wenjianming.txt










猜你喜欢

转载自blog.csdn.net/color_0716/article/details/78049452
今日推荐