2012-10-07 342 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; 

} 



}