我正在尝试在我的程序中实现 tTorrent 客户端,我查看了此链接的示例 ( https://github.com/mpetazzoni/ttorrent/issues/16 ) 并将该代码放入我的程序的 Download 类中。这是代码:
导入语句:
import main.java.com.turn.ttorrent.client.Client;
import main.java.com.turn.ttorrent.client.SharedTorrent;
import main.java.com.turn.ttorrent.common.Torrent;
import main.java.com.turn.ttorrent.tracker.TrackedTorrent;
import main.java.com.turn.ttorrent.tracker.Tracker;
// Create tracker instance
Tracker tracker = new Tracker(InetAddress.getLocalHost());
// Load torrent file
File torrentFile = new File("/path/to/torrentFile.torrent");
// Create torrent instance
TrackedTorrent torrent = new TrackedTorrent(Torrent.load(torrentFile, null));
// Announce torrent
tracker.announce(torrent);
// Start the tracker
tracker.start();
torrentFile = new File(path + ".torrent");
File downloadDir = new File("/path/to/torrents_download_dir");//unsure
Client client = new Client(InetAddress.getLocalHost(), SharedTorrent.fromFile(torrentFile, downloadDir));
// Add client.share(); if you wish to share the torrent infinitely
client.run();
当我将鼠标悬停在负载上时,收到此错误消息:
The method load(File, boolean) in the type Torrent is not applicable for the arguments (File, null)
我也不确定应该在 File downloadDir
中放置什么。我仍然是一个初学者,如果有人能指出我正确的方向,将其放入我的程序中,那就太好了。我还是个初学者。
最佳答案
Torrent.load(torrentFile, null) 想要一个 File 对象。
例如
Torrent.load(new File(/foo/path.torrent), null)
关于java - tTorrent 客户端错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22132964/