简体   繁体   中英

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 (Exception 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM