border 发表于 2013-1-16 17:42:21

通过rome读取feed,发现中文出现部分乱码。。

    用了rome 0,8的jar包,代码大部分来自于rome-samples-0.7 。
对了,放个rome的链接Rome's Home,可以直接去下载。还有就是在用rome的时候,把信息输出到xml文件里
<wbr>,部分出现乱码不知道是怎么回事<wbr>,我读的feed文件是utf-8的,我也是通过utf8读的<wbr>,但是还是有一部分乱码。今天找了一天也没有解决。。。

<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!----> 1 /*
 2  * Created on 2006-7-11
 3  *
 4  * TODO To change the template for this generated file go to
 5  * Window - Preferences - Java - Code Style - Code Templates
 6  */
 7 <span style="color: rgb(0, 0, 0);" />package border;
 8 
 9 <span style="color: rgb(0, 0, 0);" />import java.io.FileWriter;
10 <span style="color: rgb(0, 0, 0);" />import java.io.Writer;
11 <span style="color: rgb(0, 0, 0);" />import java.net.URL;
12 <span style="color: rgb(0, 0, 0);" />import java.util.List;
13 
14 <span style="color: rgb(0, 0, 0);" />import com.sun.syndication.feed.synd.SyndContent;
15 <span style="color: rgb(0, 0, 0);" />import com.sun.syndication.feed.synd.SyndEntry;
16 <span style="color: rgb(0, 0, 0);" />import com.sun.syndication.feed.synd.SyndFeed;
17 <span style="color: rgb(0, 0, 0);" />import com.sun.syndication.fetcher.FeedFetcher;
18 <span style="color: rgb(0, 0, 0);" />import com.sun.syndication.fetcher.impl.FeedFetcherCache;
19 <span style="color: rgb(0, 0, 0);" />import com.sun.syndication.fetcher.impl.HashMapFeedInfoCache;
20 <span style="color: rgb(0, 0, 0);" />import com.sun.syndication.fetcher.impl.HttpURLFeedFetcher;
21 <span style="color: rgb(0, 0, 0);" />import com.sun.syndication.io.SyndFeedOutput;
22 
23 <span style="color: rgb(0, 0, 0);" />/**
24  * @author Border
25  * 
26  * TODO To change the template for this generated type comment go to Window -
27  * Preferences - Java - Code Style - Code Templates
28  */
29 <span style="color: rgb(0, 0, 0);" />public class RSSReader {
30     private static final String feedType = "rss_2.0";
31 
32     public static void main(String[] args) throws Exception {
33 
34         String filename = "E:\\ROME\\feed_fetcher2.xml";
35         try {
36             FeedFetcherCache feedInfoCache = HashMapFeedInfoCache.getInstance();
37             FeedFetcher feedFetcher = new HttpURLFeedFetcher();
38             SyndFeed feed = feedFetcher.retrieveFeed(new URL(
39                     "http://www.blogjava.net/border/Rss.aspx"));
40 
41             feed.setFeedType(feedType);
42             feed.setTitle("Border's Blog");
43             feed.setDescription(" java Web3D FreeBsd ");
44             feed.setAuthor(" By:border ");
45             feed.setLink(" http://www.blogjava.net/border ");
46 
47             List entryList = feed.getEntries();
48 
49             for (int i = 0; i < entryList.size(); i++) {
50                 SyndEntry entry = (SyndEntry) entryList.get(i);
51 
52                 entry.setPublishedDate(entry.getPublishedDate());
53                 entry.setTitle(new String(entry.getTitle().getBytes("utf-8")));
54                 entry.setLink(entry.getLink());
55 
56                 SyndContent content = entry.getDescription();
57                 content.setValue(new String(content.getValue()
58                         .getBytes("utf-8")));
59             }
60             SyndFeedOutput output = new SyndFeedOutput();
61             Writer writer = new FileWriter(filename);
62             output.output(feed, writer);
63 
64             System.out.println("The feed has been written to the file ["
65                     + filename + "]");
66             System.out.println(" ok !");
67 
68         } catch (Exception e) {
69             System.out.println("ERROR: " + e.getMessage());
70         }
71     }
72 }
页: [1]
查看完整版本: 通过rome读取feed,发现中文出现部分乱码。。