How to upload file with relative path [duplicate]

倖福魔咒の 提交于 2019-12-08 03:28:39

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!