Search code examples
javaandroidprogramming-languages

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.


Solution

  • 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();