返回信息流问题描述如下:
在Android程序中,读取/proc/net/tcp文件获得的内容跟连接手机用adb shell命令:cat /proc/net/tcp文件中的内容不同,为什么会出现这种情况?不解求解答~非常感谢!
这是一条镜像帖。来源:北邮人论坛 / mobile-terminal-at / #33205同步于 2017/6/9
该镜像源已超过 30 天没有更新,可能在源站已被删除。
MobileTerminalAT机器人发帖
【问题求助】安卓小白遇到问题求助各位学姐学长~
yimo
2017/6/9镜像同步16 回复
订阅后,新回复会通过你的通知中心匿名送达。
9 条回复
【 在 yimo 的大作中提到: 】
: 问题描述如下:
: 在Android程序中,读取/proc/net/tcp文件获得的内容跟连接手机用adb shell命令:cat /proc/net/tcp文件中的内容不同,为什么会出现这种情况?不解求解答~非常感谢!
试了一下,测试机为中兴A2
```Java
//这个是shell:
adb shell
* daemon not running. starting it now at tcp:5037 *
* daemon started successfully *
shell@P650A30:/ $ cat /proc/net/tcp
sl local_address rem_address st tx_queue rx_queue tr tm->when retrnsmt uid timeout inode
0: 358DEB0A:86B3 8062EA0A:22B8 01 00000000:00000000 00:00000000 00000000 10117 0 42645 1 0000000000000000 36 0 0 10 -1
//这个是app里边的
private void readFile() {
File f = new File("/proc/net/tcp");
if(f.exists()){
try{
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(new FileInputStream(f)));
Log.d("xxxx", "file res:\n");
String s = null;
while ((s = stdInput.readLine()) != null) {
Log.d("xxxx", s);
}
}catch (Exception e){
e.printStackTrace();
}
}
}
private void cmd(){
try{
Runtime runtime = Runtime.getRuntime();
java.lang.Process proc = runtime.exec("cat /proc/net/tcp");
if (proc == null) {
throw new NullPointerException();
}
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(proc.getInputStream()));
Log.d("xxxx", "cmd res:\n");
String s = null;
while ((s = stdInput.readLine()) != null) {
Log.d("xxxx", s);
}
}catch (Exception e){
e.printStackTrace();
}
}
结果
06-12 11:15:05.170 8317-8317/com.ytinrete.android.lab.normal D/xxxx: cmd res:
06-12 11:15:05.183 8317-8317/com.ytinrete.android.lab.normal D/xxxx: sl local_address rem_address st tx_queue rx_queue tr tm->when retrnsmt uid timeout inode
06-12 11:15:05.183 8317-8317/com.ytinrete.android.lab.normal D/xxxx: 0: 358DEB0A:86B3 8062EA0A:22B8 01 00000000:00000000 00:00000000 00000000 10117 0 42645 1 0000000000000000 36 0 0 10 -1
06-12 11:15:05.185 8317-8317/com.ytinrete.android.lab.normal D/xxxx: file res:
06-12 11:15:05.186 8317-8317/com.ytinrete.android.lab.normal D/xxxx: sl local_address rem_address st tx_queue rx_queue tr tm->when retrnsmt uid timeout inode
06-12 11:15:05.186 8317-8317/com.ytinrete.android.lab.normal D/xxxx: 0: 358DEB0A:86B3 8062EA0A:22B8 01 00000000:00000000 00:00000000 00000000 10117 0 42645 1 0000000000000000 36 0 0 10 -1
对比
shell@P650A30:/ $ cat /proc/net/tcp
sl local_address rem_address st tx_queue rx_queue tr tm->when retrnsmt uid timeout inode
0: 358DEB0A:86B3 8062EA0A:22B8 01 00000000:00000000 00:00000000 00000000 10117 0 42645 1 0000000000000000 36 0 0 10 -1
```
## 结论:并没有发现不一样的地方,虽然不知道你读这个要干嘛
我测试出来的结果是,在shell里面要多一条记录,前面的内容跟程序打印出来的信息是一样的~
【 在 ytinrete 的大作中提到: 】
:
: [md]
: 试了一下,测试机为中兴A2
: ...................
测试出来结果如图片所示,结果是不一样的呀~
【 在 ytinrete 的大作中提到: 】
:
: [md]
: 试了一下,测试机为中兴A2
: ...................
【 在 yimo 的大作中提到: 】
: 测试出来结果如图片所示,结果是不一样的呀~
: [upload=1][/upload][upload=2][/upload]
贴一下你android代码是怎么写的
【 在 yimo 的大作中提到: 】
: 测试出来结果如图片所示,结果是不一样的呀~
: [upload=1][/upload][upload=2][/upload]
要不然你用我上面的代码看结果是不是还有少的
【 在 yimo 的大作中提到: 】
: 我就是用你那个代码试的,不知道咋回事
我这边试了3个测试机和模拟器都没有这种问题无法复现,看起来是帮不了你了
嗯嗯我用的是你的代码,只不过把log.d改成了system.out输出了,这个不应该有影响吧?
【 在 ytinrete 的大作中提到: 】
:
: 我这边试了3个测试机和模拟器都没有这种问题无法复现,看起来是帮不了你了