2012-03-30 115 views
-1

我有写这个代码,并读取文件ZIZI.txt如何在没有root权限的情况下访问写入的文件?

//=============== Write To File ZIZI.txt =============================================== 
    private void writeFileToInternalStorage() { 
     String eol = System.getProperty("line.separator"); 
     BufferedWriter writer = null; 
     try { 
      writer = new BufferedWriter(new OutputStreamWriter(openFileOutput(
       "ZIZI.txt", MODE_WORLD_WRITEABLE))); 
      writer.write("This is a test1." + eol); 
      writer.write("This is a test2." + eol); 
     } catch (Exception e) { 
       e.printStackTrace(); 
     } finally { 
      if (writer != null) { 
      try { 
       writer.close(); 
      } catch (IOException e) { 
       e.printStackTrace(); 
      } 
      } 
     } 
     Toast.makeText(getBaseContext(),"OK Save", Toast.LENGTH_SHORT).show(); 
    } 

    //================ Read From File ZIZI.txt =========================================== 
    private void readFileFromInternalStorage() { 
     String FF=""; 
     String eol = System.getProperty("line.separator"); 
     BufferedReader input = null; 
     try { 
      input = new BufferedReader(new InputStreamReader(openFileInput("ZIZI.txt"))); 
      String line; 
      StringBuffer buffer = new StringBuffer(); 
      while ((line = input.readLine()) != null) { 
       FF+=line+eol; 
      buffer.append(line + eol); 
      } 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } finally { 
     if (input != null) { 
      try { 
      input.close(); 
      } catch (IOException e) { 
       e.printStackTrace(); 
      } 
      } 
     } 
    Toast.makeText(getBaseContext(),FF, Toast.LENGTH_SHORT).show(); 
    } 

我DDMS该文件中看到:\data\data\setup.myProject\files\ZIZI.txt

但我不能看到这个文件我手机(因为我没有root权限)

我想写我的SD卡或从我的 手机中看到的任何文件夹中读取。如何更改此代码?

+0

也许你想要一个应用程序,让你看到所有文件夹(文件系统),包括根? – 2012-03-30 18:41:18

+0

我只需要知道什么改变我的代码,我可以写入和阅读文件夹,我可以在手机上看到 – Gold 2012-03-30 19:00:54

回答

0

有你从未使用过Android Developers website?

尝试开发指南 - >数据存储 - >Using the External Storage

+0

我讨厌这个网站(Android开发者网站)我总是去那里失去。我只需要知道在我的代码中要更改什么,以便我可以在手机上看到并阅读到文件夹。 – Gold 2012-03-30 19:00:27

0

你需要指定整个路径到您的文件,即使用getFilesDir内部存储或getExternalFilesDir()用于外部存储。例如:

openFileInput(getExternalFilesDir(null) + "/" + "ZIZI.txt"); 
相关问题