2014-02-06 75 views
1

任何人都可以通过android应用程序以编程方式帮助我在Android设备中读取/data/misc/wifi/wpa_supplicant.conf文件。如何阅读wpa_supplicant.conf文件

我试过下面的代码来读取存储在wpa_supplicant.conf文件中的信息并在textview中显示信息,但它什么都不返回。

try 
{ 

    Process psProc = Runtime.getRuntime().exec(new String[]{"su","-c"});//root 
    File path=Environment.getDataDirectory(); 
    File myFile = new File("/data/misc/wifi/wpa_supplicant.conf"); 
    FileInputStream fIn = new FileInputStream(myFile); 
    BufferedReader myReader = new BufferedReader(
    new InputStreamReader(fIn)); 
    String aDataRow = ""; 
    String aBuffer = ""; 
    while ((aDataRow = myReader.readLine()) != null) { 
     aBuffer += aDataRow + "\n"; 
    } 
    tv.setText(aBuffer); 
    myReader.close(); 
    Toast.makeText(getBaseContext(),"Done reading SD 'TextAreaAppender.java'", 
       Toast.LENGTH_SHORT).show(); 
} 
catch (Exception e) 
{ 
    Toast.makeText(getBaseContext(), e.getMessage(),Toast.LENGTH_LONG).show(); 
    tv.setText(e.getMessage()); 
} 

Textview什么都不显示。

回答

1

请确保您已重新安装分区。否则,您无权在此处读取/写入。

在对该文件夹进一步操作之前,您可以尝试以下步骤。

Runtime.getRuntime().exec("system/bin/mount -o rw,remount -t rootfs /data"); 
Runtime.getRuntime().exec("system/bin/chmod 777 /data/misc/wifi"); 
+0

感谢replay..i会尝试这个.. – user3278265

+0

@Junyong我写的授予超级用户access.i'v尝试这种代码的应用程序,但我得到许可被拒绝:/数据/其它/ WIFI /的wpa_supplicant .conf:打开失败:EACCES(权限被拒绝)。有没有解决方法? –