①代码:http://feeds.qzone.qq.com/cgi-bin/cgi_rss_out?uin=QQ号码
主要难点在于URL获得, 其他简单:
package test; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpMethod; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.httpclient.params.HttpMethodParams; public class QQBlog { public static void main(String[] args) throws Exception { getBlog(); } public static void getURL() throws Exception{ String urlString= ""; URL url = new URL(urlString); // http://h5.qzone.qq.com/ugc/share?subtype=0&sk=&blog_photo=0&appid=2&ciphertext=696787C2AB42A61C2E27685CEE36AF9796854678E0B93AEFF61B57E96CB504643D243384B5184728762F01C1DCEB0F0C&g_f= // http://b.qzone.qq.com/cgi-bin/blognew/blog_output_data?bdm=b.qzone.qq.com&blogid=&imgdm=ctc.qzs.qq.com&mode=2&numperpage=15&property=GoRE&uin=QQ号码 // http://b.qzone.qq.com/cgi-bin/blognew/blog_get_titlelist?uin=635998173&vuin=0&property=GoRE&category=&numperpage=100&pos=0&direct=1 // http://user.qzone.qq.com/635998173/blog/1441881523 // http://feeds.qzone.qq.com/cgi-bin/cgi_rss_out?uin=635998173 // http://url.cn/e9gVNW HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.connect(); InputStream urlStream = connection.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader( urlStream)); String tmp = ""; StringBuffer sb = new StringBuffer(); while ((tmp = reader.readLine()) != null) { sb.append(tmp); } System.out.println(sb.toString()); } public static void getBlog() { HttpClient client = new HttpClient(); HttpMethod method = null; String charset = "utf-8"; String urlString= ""; method = new GetMethod(urlString); method.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, charset); int status = 0; try { status = client.executeMethod(method); } catch (HttpException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } if (status != HttpStatus.SC_OK) { return; } BufferedWriter bw = null; try { String toWrite = method.getResponseBodyAsString(); if (toWrite != null) { File file = new File("d://abc.txt"); if (!file.exists()) { file.createNewFile(); } bw = new BufferedWriter(new FileWriter(file)); bw.write(toWrite); System.out.println(toWrite.toString()); } } catch (IOException e) { e.printStackTrace(); } finally { method.releaseConnection(); if (bw != null) { try { bw.flush(); bw.close(); } catch (IOException e) { e.printStackTrace(); } } } } }
相关推荐
java URL转PDF文件,网页内容转PDF文件
JAVA 根据Url 接口 获取文件名称和类型,亲测可用。输入参数地址即可。
JAVA解决URL路径中含有中文的问题。无论是路径中还是文件名包含中文都可以处理。经测试验证通过。
java通过url调用外部接口,返回字符串,再讲字符串解析成json格式。包含源码和jar包,直接运行即可,带注释。
java 使用URL访问网页 java 使用URL访问网页 java 使用URL访问网页
\java通过url在线预览Word、excel、ppt、pdf、txt文档中的内容 \java通过url在线预览Word、excel、ppt、pdf、txt文档中的内容
利用java 读取URL的资源,并且把读取到的资源写入到指定路径的文件中。
java URL转PDF文件(完美支持中文).解决linux中不显示中文问题:http://blog.csdn.net/zxz547388910/article/details/74315277
JAVA通过url获取网页内容
java语音调用已经安装的windows浏览器,打开指定的URL地址
Java源代码根据URL获取因特网网页源文件.rar
利用syslog协议 ,发送网络安全设备日志。java版
基于java的开发源码-日志服务器 Apache Flume.zip 基于java的开发源码-日志服务器 Apache Flume.zip 基于java的开发源码-日志服务器 Apache Flume.zip 基于java的开发源码-日志服务器 Apache Flume.zip 基于java的...
java利用URL获取网页内容,
java工具实现类-根据网站链接url,生成二维码图片,存放本地目录
java 写日志记录到指定目录下(一天一个文档)
自定义日志模块(接口及代理实现),而不直接使用第三方日志框架接口,避免在日志框架升级或者切换时,代码过多耦合。 这个举例说明一下: 比如,在某一项目开始时使用的是“log4j”框架,后面经过研究发现“sf4j...
java URL授权访问 , 提交的时候增加 用户有授权.