1

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?

Community
  • 1
  • 1
ChanChow
  • 1,346
  • 7
  • 28
  • 57
  • Yup. It is duplicate of it. Can you give me syntax how to access it. The duplicate one didn't provide any code. – ChanChow Oct 19 '12 at 06:59

1 Answers1

0

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");
AAnkit
  • 27,299
  • 12
  • 60
  • 71
  • I am trying this code File dir = Environment.getExternalStorageDirectory(); File f_path = new File(dir, url); InputStream fis = null; fis = new BufferedInputStream(new FileInputStream(f_path)); when I run this it is returning me java.io.FileNotFoundException: /mnt/sdcard/sdcard/download/xyx.txt (No such file or directory) Can you tell me what is wrong with it? – ChanChow Oct 20 '12 at 06:18