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 に答える