简体   繁体   English

Android使用ftp API保存到内部存储器

[英]Android save to internal memory using ftp api

im using ftp4j to connect and download a file via ftp 即时通讯使用ftp4j通过ftp连接并下载文件

The following works to save to the emulated sdcard. 以下工作可保存到模拟的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? 我该如何保存到内部存储器中,以便将test.jpg加载到图像视图中?

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. 流式传输文件并将该流转换为jpg格式的位图并加载该位图。

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.. 您已经拥有流文件的一部分,现在需要将该文件转换为jpg格式的位图,以加载到imageview中。

so pseudo code wise it would be: 所以明智的伪代码将是:

Bitmap ourBitmap = create bitMapfromurl(url); 位图ourBitmap =创建bitMapfromurl(url); Imageview ourImageView = loadbitmap(bitmap); Imageview ourImageView = loadbitmap(bitmap);

Your url will the sdcard url to the test.jpg file. 您的网址将是sdcard网址到test.jpg文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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