0
我有這個問題,我想我在這裏丟失了一些東西。我的項目需要訪問FTP服務器來下載一些特定的圖像,但我使用的代碼似乎不工作,請注意,我使用相同的代碼來下載一些文本文件,它的工作正常!無法從FTP服務器下載圖像
這裏是我的代碼:
*注:我使用Apache公地ftpclient ..
try {
File Imgfile = new File(Environment.getExternalStorageDirectory(), "img.jpg");
BufferedOutputStream buffIn = new BufferedOutputStream(new FileOutputStream(Imgfile)); // local location
con.retrieveFile("/public_html/cam.jpg", buffIn);
buffIn.close();
} catch (IOException e) {
Toast customToast = new Toast(getBaseContext());
customToast = Toast.makeText(getBaseContext(), "Cannot Downlaod the image" , Toast.LENGTH_SHORT);
customToast.setGravity(Gravity.TOP|Gravity.LEFT, 150, 450);
customToast.show();
}
我也試過這樣:
InputStream Fstream = null;
try {
Fstream = con.retrieveFileStream("/public_html/out.jpg");
bitmap = BitmapFactory.decodeStream(Fstream);
FileOutputStream stream = new FileOutputStream(mFilePath);
bitmap.compress(CompressFormat.JPEG, 100, stream);
stream.flush();
stream.close();
buffIn.flush();
buffIn.close();
Fstream.close();
} catch (IOException e) {
Toast customToast = new Toast(getBaseContext());
customToast = Toast.makeText(getBaseContext(), "Cannot Downlaod the image" , Toast.LENGTH_SHORT);
customToast.setGravity(Gravity.TOP|Gravity.LEFT, 150, 450);
customToast.show();
}
我總是得到這個嘗試/ catch message「Can not Downlaod the image」,
請直到我最近錯了什麼,或者指向正確的方向。
在此先感謝