Android save to internal memory using ftp api
im using ftp4j to connect and download a file via ftp
The following works to save to the emulated 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 (Exceptio开发者_如何学编程n ex) {
Toast.makeText(ftpactivity.this, ex.toString(),
Toast.LENGTH_SHORT).show();
}
How can I save to the internal memory instead so that the test.jpg can be loaded into an imageview?
Sorry for my noobness and thanks in advance.
Following code might give you an idea to save a file in internal memory -
String FILENAME = "hello_file";
String string = "hello world!";
FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
fos.write(string.getBytes());
fos.close();
Stream the file and convert that stream to jpg formated bitmap and load the bitmap.
You already have part of it the streaming file part you now need to convert that file to a bitmap formated in jpg to load into the imageview..
so pseudo code wise it would be:
Bitmap ourBitmap = create bitMapfromurl(url); Imageview ourImageView = loadbitmap(bitmap);
Your url will the sdcard url to the test.jpg file.
精彩评论