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");

谢谢,

4

1 回答 1

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;

 }



}
于 2012-10-07T13:50:02.343 回答