网络获取数据sd卡读取

来源:互联网 发布:c语言编译环境 编辑:程序博客网 时间:2024/05/17 22:03
 //写入
File file = new File(Environment.getExternalStorageDirectory().getPath() + "/city.txt");    if (file.exists()) {        try {            FileInputStream stream = new FileInputStream(file);            ByteArrayOutputStream bos = new ByteArrayOutputStream();            int len;            byte[] b = new byte[1024];            while ((len = stream.read(b)) != -1) {                bos.write(b, 0, len);            }            bos.close();            stream.close();            String s = bos.toString();            getData(s);        } catch (Exception e) {            e.printStackTrace();        }    }else{        //获取网络数据        getServerData();    }}
//读取
File file= Environment.getExternalStorageDirectory();File file1=new File(file.getPath()+"/city.txt");PrintWriter pw=null;if (!file1.exists()){    try {        file1.createNewFile();    } catch (IOException e) {        e.printStackTrace();    }}try {    pw=new PrintWriter(new FileOutputStream(file1));    pw.write(s);    pw.close();} catch (FileNotFoundException e) {    e.printStackTrace();}getData(s);

0 0
原创粉丝点击