File file1 = null,file2=null,file3=null,file4=null; Date date2 = new Date(); SimpleDateFormat format2 = new SimpleDateFormat("yyyyMMdd"); //获取项目文件files的目录 File tempFile = this.getFilesDir(); String yygypathstr = tempFile.toString(); //文件命名格式为以时间(年月日)+资源名 file1 = new File(yygypathstr, (format2.format(date2)+"VICE中国"+ ".xml")); file2 = new File(yygypathstr, (format2.format(date2)+"设计癖"+ ".xml")); file3 = new File(yygypathstr, (format2.format(date2)+"知乎"+ ".xml")); file4 = new File(yygypathstr, (format2.format(date2)+"豆瓣一刻"+ ".xml")); //如果文件不存在,才创建 if (!file1.exists() && !file2.exists() && !file3.exists() && !file4.exists()) { try { file1.createNewFile(); file2.createNewFile(); file3.createNewFile(); file4.createNewFile(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
Date date = new Date(); SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd"); String paperTitleName=format.format(date)+title+ ".xml"; File file=null; File fileXml=new File(xmlPath.toString()); File[] tempList = fileXml.listFiles(); //点击那一份杂志,找到这份杂志的当天xml赋给file for (int i = 0; i < tempList.length; i++) { if (paperTitleName.equals(tempList[i].getName())) { file=tempList[i]; } }如果不为空就不存入数据
HttpClient client = new DefaultHttpClient(); HttpGet get = new HttpGet(RSS_URL); try { HttpResponse response = client.execute(get); if (response.getStatusLine().getStatusCode() == 200 && file.length()==0) { InputStream inputStream = response.getEntity().getContent(); FileOutputStream fos = new FileOutputStream(file); int byteread = 0; byte[] buffer = new byte[1024]; while ((byteread = inputStream.read(buffer)) != -1) { fos.write(buffer, 0, byteread); } fos.flush(); fos.close(); inputStream.close(); } } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }存入数据之后,开始解析xml文件读取数据,方法和我之前写的如何读取xml的方法一样。明天我将完成如何向下滑动,刷新出昨天的文章。
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/u012157999/article/details/47785749