1) 安装 maven,查看如何使用 maven 启动一个快速的“Hello World”项目。一旦你掌握了它,添加
<dependency>
<groupId>com.turn</groupId>
<artifactId>ttorrent</artifactId>
<version>1.4</version>
</dependency>
到你的 pom.xml
2)从您链接的页面:
// First, instantiate the Client object.
Client client = new Client(
// This is the interface the client will listen on (you might need something
// else than localhost here).
InetAddress.getLocalHost(),
// Load the torrent from the torrent file and use the given
// output directory. Partials downloads are automatically recovered.
SharedTorrent.fromFile(
new File("/path/to/your.torrent"),
new File("/path/to/output/directory")));
// You can optionally set download/upload rate limits
// in kB/second. Setting a limit to 0.0 disables rate
// limits.
client.setMaxDownloadRate(50.0);
client.setMaxUploadRate(50.0);
// At this point, can you either call download() to download the torrent and
// stop immediately after...
client.download();
// Or call client.share(...) with a seed time in seconds:
// client.share(3600);
// Which would seed the torrent for an hour after the download is complete.
// Downloading and seeding is done in background threads.
// To wait for this process to finish, call:
client.waitForCompletion();
// At any time you can call client.stop() to interrupt the download.