我遇到了这个问题,我认为这里缺少一些东西。我的项目需要访问 FTP 服务器来下载一些特定的图像,但是我使用的代码似乎不起作用,请注意,我使用相同的代码来下载一些文本文件,它工作得很好!!!!
这是我的代码:
*注意:我正在使用 Apache commons 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();
}
我总是收到这条 try/catch 消息“无法下载图像”,
请告诉我出了什么问题,或者指出我正确的方向。
提前致谢