2012-04-16 63 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(); 
} 
相關問題