请问如何获取系统路由表信息。 hi~ 大大们,请问有API可疑获取系统路由表信息吗?或者是否可以通过Runtime.getRuntime().exec("busybox route")之类的操作来读取?怎么实现会简单些呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 可以使用busybox routetry { // Executes the command. Process process = Runtime.getRuntime().exec("busybox route"); BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); int read; char[] buffer = new char[4096]; StringBuffer output = new StringBuffer(); while ((read = reader.read(buffer)) > 0) { output.append(buffer, 0, read); } reader.close(); // Waits for the command to finish. process.waitFor(); return output.toString(); //获得输出} catch (IOException e) { throw new RuntimeException(e);} catch (InterruptedException e) { throw new RuntimeException(e);} 谢谢你提供的方案,我使用这个方法的时候,碰到如下异常:06-30 05:35:05.182: ERROR/AndroidRuntime(327): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.David/com.android.David.LogTest1Activity}: java.lang.RuntimeException: java.io.IOException: Error running exec(). Command: [busybox, route] Working Directory: null Environment: null06-30 05:35:05.182: ERROR/AndroidRuntime(327): Caused by: java.lang.RuntimeException: java.io.IOException: Error running exec(). Command: [busybox, route] Working Directory: null Environment: null06-30 05:35:05.182: ERROR/AndroidRuntime(327): Caused by: java.io.IOException: Error running exec(). Command: [busybox, route] Working Directory: null Environment: null06-30 05:35:05.182: ERROR/AndroidRuntime(327): Caused by: java.io.IOException: Permission denied请问这个操作需要什么permission呢? 我试过可以获取得到 不用什么权限 你直接adb shell busybox route有显示吗? 呃。我试了一下, device上可以成功,但是用Emulator就报了上面的exception.不过问题算是解决啦。非常感谢! Activity模拟器横竖屏转换的问题 关于AnimationSet使用过程出现的一些问题 android官方的api里面有资源管理器吗? PC通过局域网监控android设备 发布apk的时候为什么要用keystore做签名 tabhost 中的Activity防止重新启动问题 FragmentTabHost中子项Fragment加载问题 Android中主动获取基站信号强度 -- 不是监听信号改变 Android无屏幕调试 listview分页加载后出现重复数据不知道什么问题 android flipper的问题 万急求助~~从android浏览器中启动控件
try {
// Executes the command.
Process process = Runtime.getRuntime().exec("busybox route");
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
int read;
char[] buffer = new char[4096];
StringBuffer output = new StringBuffer();
while ((read = reader.read(buffer)) > 0) {
output.append(buffer, 0, read);
}
reader.close();
// Waits for the command to finish.
process.waitFor();
return output.toString(); //获得输出
} catch (IOException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
06-30 05:35:05.182: ERROR/AndroidRuntime(327): Caused by: java.lang.RuntimeException: java.io.IOException: Error running exec(). Command: [busybox, route] Working Directory: null Environment: null06-30 05:35:05.182: ERROR/AndroidRuntime(327): Caused by: java.io.IOException: Error running exec(). Command: [busybox, route] Working Directory: null Environment: null06-30 05:35:05.182: ERROR/AndroidRuntime(327): Caused by: java.io.IOException: Permission denied请问这个操作需要什么permission呢?