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

来源:互联网 发布:知乎 宋徽宗 编辑:程序博客网 时间:2024/06/05 00:16


/**用这个方法需要加权限 * 往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










阅读全文
0 0