2012-10-07 302 views
0

我試圖讀取文本文件並將這些文本文件中的數據插入到URL中; 但我有這個錯誤 「java.lang.IllegalArgumentException異常包含一個路徑分隔文件」從文本文件中讀取數據

這是讀出方法,即時通訊使用

>

public String ReadFile (String Path){ 
    String  res = null; 
    try { 
     String filePath = android.os.Environment.getExternalStorageDirectory().getPath() + "/" + Path; 

     File file = new File(filePath); 
     if(file.exists()){ 
      InputStream  in = openFileInput(filePath); 

      if (in != null) { 
      // prepare the file for reading 
      InputStreamReader input = new InputStreamReader(in); 
      BufferedReader buffreader = new BufferedReader(input); 

       res = ""; 
       String line; 
      while ((line = buffreader.readLine()) != null) { 
       res += line; 
       } 
       in.close(); 

       }else{ 
      } 
     }else{ 
       Toast.makeText(getApplicationContext(), "The File" + Path + " not Found" ,Toast.LENGTH_SHORT).show(); 
     } 
    } catch(Exception e){ 
      Toast.makeText(getApplicationContext(),e.toString() + e.getMessage(),Toast.LENGTH_SHORT).show(); 
    } 
    return res; 
} 



    > String sendername = ReadFile ("SenderName.txt"); 
    String AccountName = ReadFile ("AccountName.txt"); 
    String AccountPassword = ReadFile ("AccountPassword.txt"); 
    String MsgText = ReadFile ("MsgText.txt"); 

謝謝,

回答

0

-雖然這個錯誤並沒有指出那裏,但你仍然有權利閱讀Manifest.xml文件中的外部存儲

嘗試是這樣的..

public void readFile(String path){ 


File f = new File(path); 
FileReader fr = new FileReader(f); 
BufferedReader br = new BufferedReader(fr); 

String read = new String(); 

String temRead = new String(); 

while((temRead = br.readLine())!=null){ 

    read = read + temRead; 

} 



}