この問題が発生していて、ここで何かが足りないと思います。私のプロジェクトは特定の画像をダウンロードするためにFTPサーバーにアクセスする必要がありますが、使用しているコードが機能していないようです。同じコードを使用していくつかのテキストファイルをダウンロードしており、正常に機能していることに注意してください!!!!
これが私のコードです:
*注:Apachecommonsftpclientを使用しています。
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メッセージ「画像をダウンロードできません」を受け取ります。
何が悪いのか私まで言ってください、または私を正しい方向に向けてください。
前もって感謝します