用的是 jBittorrentAPI.jar 解析种子文件。
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
// t1();
Object a = new Object();
File f = new File("c:\\a.torrent");
InputStream in = new FileInputStream(f);
BufferedInputStream is = new BufferedInputStream(in);
Map<String, Object> m = BDecoder.decode(is);
System.out.println("通过Map.keySet遍历key和value:");
for (String key : m.keySet()) {
System.out.println("key= " + key + " and value= " + m.get(key));
}
Map<String,Object> info = (Map) m.get("info");
Object param = info.get("name");
//这个 param 是个 int数组,但是强转却出现强制类型转换错误。。想不明白
}



接着问题又来了,种子内的文件名 理论上是 ascii 编码,但是我发现如果包含中文 就会出现负数 。。。ascii编码里没有负数,那这个是数字是什么,怎么变成中文。。
-25
-89
-69
-27
-118
-88
-24
-65
-73
-27
-82
-85
46
66
68
46
55
50
48
112
46
-27
-101
-67
-24
-117
-79
-27
-113
-116
-24
-81
-83
46
-28
-72
-83
-24
-117
-79
-27
-113
-116
-27
-83
-105
-27
-71
-107
46
109
107
118
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
試試cast成String
请问哪里看出param是个
int数组了?报错信息中提示param的类型是
[B, 也就是byte[],不能转化为[Ljava.lang.Integerhttp://docs.oracle.com/javase/6/docs/api/java/lang/Class.html#getName%28%29
java中的 byte是
有符号的,一个字节的范围是0~255, 转化成有符号数字,就变成了byte[]转化成String ,用
另外你又哪里看出来是
ascii编码了。。 汉字几千个,ascii码才127个。。。一个字节,ascii码只占了一半的空间,剩下的都被其他编码用了,用于扩充各国语言,具体不展开了, 百度搜索gbk、utf-8、unicode之类的先了解一下
你是怎么转的?把转换代码和报错信息贴一下看看。
已实测 请看:
public static void main(String[] args) {
}
//输出:
10
84
101
46。
补充一点:思路 byte[]不能直接转int[],但byte可以转int,for循环一个一个来即可。