[英]Android save to internal memory using ftp api
即時通訊使用ftp4j通過ftp連接並下載文件
以下工作可保存到模擬的sdcard中。
try {
client.login(username, password);
client.download("test.jpg", new java.io.File("/sdcard/test.jpg"));
Toast.makeText(ftpactivity.this, "download complete",
Toast.LENGTH_SHORT).show();
} catch (Exception ex) {
Toast.makeText(ftpactivity.this, ex.toString(),
Toast.LENGTH_SHORT).show();
}
我該如何保存到內部存儲器中,以便將test.jpg加載到圖像視圖中?
抱歉,我很無聊,在此先感謝。
以下代碼可能會給您一個將文件保存在內部存儲器中的想法-
String FILENAME = "hello_file";
String string = "hello world!";
FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
fos.write(string.getBytes());
fos.close();
流式傳輸文件並將該流轉換為jpg格式的位圖並加載該位圖。
您已經擁有流文件的一部分,現在需要將該文件轉換為jpg格式的位圖,以加載到imageview中。
所以明智的偽代碼將是:
位圖ourBitmap =創建bitMapfromurl(url); Imageview ourImageView = loadbitmap(bitmap);
您的網址將是sdcard網址到test.jpg文件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.