编辑文件p2p_supplicant.conf中的值,该文件位于/root/data/misc/wifi/p2p_supplicant.conf

时间:2015-04-22 11:03:23

标签: android randomaccessfile

我正在尝试开发一个函数来编辑根文件p2p_supplicant.conf中的值,该文件位于/root/data/misc/wifi/p2p_supplicant.conf

toast消息始终显示" File Not Found" 我的代码是:

   private static final String FILE_PATH = "/root/data/misc/wifi/p2p_supplicant.conf";
   private static final String MARKER_LINE = "p2p_oper_channel=";
   private static final String TEXT_TO_ADD = "11";

public void changeConfig() {

     String message = String.format("Entering Config Class");
     Toast.makeText(getApplicationContext(), message,Toast.LENGTH_LONG).show();

          List<String> fileLines = new ArrayList<String>();
          Scanner scanner = null;
          try {
             scanner = new Scanner(new File(FILE_PATH));
             while (scanner.hasNextLine()) {
                String line = scanner.nextLine();
                fileLines.add(line);
                if (line.trim().equalsIgnoreCase(MARKER_LINE)) {
                   fileLines.add(TEXT_TO_ADD);

                     String message2 = String.format("File Written");
                     Toast.makeText(getApplicationContext(), message2,Toast.LENGTH_LONG).show();
                }
             }

          } catch (FileNotFoundException e) {
             e.printStackTrace();
             String message1 = String.format("File Not found");
             Toast.makeText(getApplicationContext(), message1,Toast.LENGTH_LONG).show();
          } finally {
             if (scanner != null) {
                scanner.close();
             }
          }

          PrintWriter pw = null;
          try {
             pw = new PrintWriter(new File(FILE_PATH));
             for (String line : fileLines) {
                pw.println(line);
             }
          } catch (FileNotFoundException e) {
             e.printStackTrace();
          } finally {
             if (pw != null) {
                pw.close();
             }
          }
        }

但是代码没有找到文件的位置/路径。请建议。 注:我的手机扎根了。

0 个答案:

没有答案