问题
Possible Duplicate:
java.lang.IllegalArgumentException: contains a path separator
I am trying to upload a file from my sdcard, file path url="sdcard/Folder/test.doc". I am using the following code to upload to server.
String url = path.getText().toString();
FileInputStream fis = openFileInput(url);
It is giving me error :
FATAL EXCEPTION: main 10-19 01:19:39.480: E/AndroidRuntime(7459): java.lang.IllegalArgumentException: File /sdcard/download/ABC.pdf contains a path separator.
Can some one please tell me how to get it done?
回答1:
openFileInput(url);
can not open file stored on sdcard. this method is used to Open a private file associated with this Context's application package for reading.
you must use new File(path)
method to create or open a file. then use appropriate InputStream. can refer below syntax..
File dir = Environment.getExternalStorageDirectory();
File yourFile = new File(dir, "path/to/the/file/inside/the/sdcard.ext");
来源:https://stackoverflow.com/questions/12968618/how-to-upload-file-with-relative-path