我想使用(“ /sdcard/file.torrent”)上已保存的.torrent文件开始简单下载。
我尝试过ttorrent,因为它是最简单的bittorrent客户端。
ttorrent on github.com
所以我尝试了这段代码,但是有错误...
String filePath = "/sdcard/file.torrent";
String downPath = "/sdcard/A";
Client client = new Client (
InetAddress.getLocalHost(),
SharedTorrent.fromFile(
new File(filePath),
new File(downPath)
)
);
client.setMaxDownloadRate(0.0);
client.setMaxUploadRate(0.0);
client.download();
client.share(0);
client.waitForCompletion();
日志:
E/AndroidRuntime(5992): FATAL EXCEPTION: main
E/AndroidRuntime(5992): java.lang.NoSuchMethodError: org.apache.commons.codec.binary.Hex.encodeHex
E/AndroidRuntime(5992): at com.turn.ttorrent.common.Torrent.byteArrayToHexString(Torrent.java:415)
E/AndroidRuntime(5992): at com.turn.ttorrent.common.Torrent.<init>(Torrent.java:145)
E/AndroidRuntime(5992): at com.turn.ttorrent.client.SharedTorrent.<init>(SharedTorrent.java:175)
E/AndroidRuntime(5992): at com.turn.ttorrent.client.SharedTorrent.<init>(SharedTorrent.java:159)
E/AndroidRuntime(5992): at com.turn.ttorrent.client.SharedTorrent.fromFile(SharedTorrent.java:239)
E/AndroidRuntime(5992): at com.torrentsearch.activities.ResultList.onContextItemSelected(ResultList.java:435)
E/AndroidRuntime(5992): at android.app.Activity.onMenuItemSelected(Activity.java:2647)
E/AndroidRuntime(5992): at com.android.internal.policy.impl.PhoneWindow$DialogMenuCallback.onMenuItemSelected(PhoneWindow.java:3921)
E/AndroidRuntime(5992): at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
E/AndroidRuntime(5992): at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:149)
E/AndroidRuntime(5992): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
E/AndroidRuntime(5992): at com.android.internal.view.menu.MenuDialogHelper.onClick(MenuDialogHelper.java:193)
E/AndroidRuntime(5992): at com.android.internal.app.AlertController$AlertParams$3.onItemClick(AlertController.java:934)
E/AndroidRuntime(5992): at android.widget.AdapterView.performItemClick(AdapterView.java:301)
E/AndroidRuntime(5992): at android.widget.AbsListView.performItemClick(AbsListView.java:1280)
E/AndroidRuntime(5992): at android.widget.AbsListView$PerformClick.run(AbsListView.java:3071)
E/AndroidRuntime(5992): at android.widget.AbsListView$1.run(AbsListView.java:3973)
E/AndroidRuntime(5992): at android.os.Handler.handleCallback(Handler.java:615)
E/AndroidRuntime(5992): at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime(5992): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(5992): at android.app.ActivityThread.main(ActivityThread.java:4921)
E/AndroidRuntime(5992): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(5992): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(5992): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
E/AndroidRuntime(5992): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
E/AndroidRuntime(5992): at dalvik.system.NativeStart.main(Native Method)
最佳答案
问题出在apache-commons lib中。我使用的是1.8(最新版本),但此ttorrent客户端1.2 version是必需的。client.setMaxDownloadRate(0.0);
0.0设置下载速度无限制。但是下载速度太慢,Android uTorrent的功能更多。