0

在Android系统中,我想读取文件“/proc/net/xt_qtaguid/stats”。但是,如果未能阅读第二行。读取第一行就成功了。但是,hasNextLine() 返回 false,这使得无法读取下一行。

代码如下:

    File statsFile = new File("/proc/net/xt_qtaguid/stats");
    Scanner scanner = null;
    try {
        scanner = new Scanner(statsFile);
        while (scanner.hasNextLine()) {
            String line = scanner.nextLine();
            Log.d(TAG, "hasNextLine(): " + scanner.hasNextLine());

这是我试图阅读的统计文件。该文件在这篇文章中看起来像一行。但是,每行以“0x0A”结尾,并显示为 3 行。

idx iface acct_tag_hex uid_tag_int cnt_set rx_bytes rx_packets tx_bytes tx_packets rx_tcp_bytes rx_tcp_packets rx_udp_bytes rx_udp_packets rx_other_bytes rx_other_packets tx_tcp_bytes tx_tcp_packets tx_udp_bytes tx_udp_packets tx_other_bytes tx_other_packets 2 wlan0 0x0 0 0 1129 10 2066 32 80 2 1049 8 0 0 0 0 530 8 1536 24 3 wlan0 0x0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

4

1 回答 1

2

尝试使用良好的旧阅读器类:

try {
    File statsFile = new File("/proc/net/xt_qtaguid/stats");
    BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(statsFile)));

    String line;
    while((line = br.readLine()) != null){
        Log.d(TAG, "readline(): " + line);
    }

    br.close();
} catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
于 2012-04-16T07:02:27.923 回答