我遇到了这个问题,我想在这里遗漏了一些东西。我的项目需要访问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();
}
我总是得到这个尝试/捕获消息“不能下载图像”,
请告诉我错误,或指出我正确的方向。
提前致谢