碰到不會的技術問題,我還是先度娘。能中文看懂,為什么非要看英文呢。
java 解析/讀取 種子/bt/torrent 內容,這個度娘給的滿意答案並不是很多。GG之后的搜索結果出現了stackoverflow這個網站,技術人員都懂的,基本有解決方案了,猶如黑暗里的螢火蟲,早期度娘java問題的javaeye。
有3種解決方案
1、不適用第三方jar,可以看看 http://blog.csdn.net/phinecos/article/details/4611924。 度娘給的基本都是這種解決方案。順便鄙視下國內的某些程序員,轉載別人的文章時,也不測試下,結果1傳10,10傳100,都是有bug的。
2、使用jbittorrent api,說實話,沒研究怎么玩。由於本人已離開了這個行業,適用為主。
3、Eclipse ecf,第一次聽說,不懂的同學自己度娘或GG。實際上是一個插件,進入eclipse官網,下載壓縮包,比較大(16.1M),因為我們要的只是解析BT,只需要其中的一個jar文件即可。打開壓縮包,在 plugins 目錄下,找到以下文件
我們只需要第二個即可,也不大,74K。
這是在線API地址:http://www.eclipse.org/ecf/org.eclipse.ecf.docs/api/org/eclipse/ecf/protocol/bittorrent/TorrentFile.html
接下來就純Demo
1 import org.eclipse.ecf.protocol.bittorrent.TorrentFile; 2 3 public class Test 4 { 5 public static void main(String[] args) throws Exception 6 { 7 String path = "d:/0623060253062306025306.torrent"; 8 9 TorrentFile file = new TorrentFile(new File(path)); 10 11 String[] strs = file.getFilenames(); 12 long[] longs = file.getLengths(); 13 System.out.println(strs.length + " " + longs.length); 14 15 for(int i = 0; i < strs.length; i ++) 16 { 17 System.err.println(strs[i] + " ---> " + longs[i]); 18 } 19 20 21 } 22 }
顯示結果,大家自己加table或者div就OK。
如下是迅雷解析BT,我們現在也能實現如下效果了。