2012-04-16 64 views
0

在Android系统中,我想读取文件“/ proc/net/xt_qtaguid/stats”。但是,如果未能读取第二行。 阅读第一行是成功的。但是,hasNextLine()返回false,这使得不可能读取下一行。在Android系统中,阅读第一行后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

+0

@如果从文件中读取,为什么不使用一些“读者” – Jayan 2012-04-16 05:59:45

回答

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(); 
} 
相关问题