views:

61

answers:

1

When implementing download function it work but during file saving to sdcard i get the following

Default buffer size used in BufferedInputStream constructor. It would be better to be explicit if an 8k buffer is required.

Also IO Exception occure

W(14495:0x389f) java.io.FileNotFoundException: /sdcard W(14495:0x389f) at org.apache.harmony.luni.platform.OSFileSystem.open(OSFileSystem.java:244) W(14495:0x389f) at java.io.FileOutputStream.(FileOutputStream.java:97) W(14495:0x389f) at java.io.FileOutputStream.(FileOutputStream.java:168) W(14495:0x389f) at java.io.FileOutputStream.(FileOutputStream.java:147)

+1  A: 

First make sure you get the File object by calling

File dir = Environment.getExternalStorageDirectory();

Also if you app is using 1.6+ you will need the WRITE_EXTERNAL_STORAGE permission. If that doesn't help, post the code.

BrennaSoft
I have use BufferedInput stream BufferedInputStream bis = new BufferedInputStream(objectComplete.getDataInputStream()); BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("/sdcard"));int i;while ((i = bis.read()) != -1) {bos.write(i);System.out.println("Writing file");}System.out.println("Greeting:");also i have set permission to writiong on sdcard<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Ahmed Salem
@Ahmed Salem: Please read the answer you were given. It does not match your code. Your code hardwires `"/sdcard"`. That is not a valid path on all Android devices. You will notice that BrennaSoft's answer does not hardwire `"/sdcard"`, but rather uses `Environment.getExternalStorageDirectory()`. Modify your code to use `Environment.getExternalStorageDirectory()`, and you may have better luck.
CommonsWare
@CommonsWareei have change code and still have exception java.io.FileNotFoundException: /sdcard
Ahmed Salem