使用commons-net ftp api。我想下载文件,但此文件大小为0

时间:2012-10-23 10:07:36

标签: java android ftp apache-commons-net

我使用commons-net-3.1库制作简单的应用程序 我想从FTP服务器下载文件,但下载文件的大小为0 这个文件名是英文混合,符号(如“ - ”,“_”等等),其他语言(如韩语,日语等)。 如何解决这个问题? T.T

这是代码

/**
 * download file. it works thread
 * 
 * @param source
 *            file path witch is remote path
 * @param destination
 *            file path witch is saving local memory
 */
public void downloadFile(String source, String destination) {
    DownloadTempFile download = new DownloadTempFile(source, destination);
    download.setDaemon(true);
    download.start();
}

class DownloadTempFile extends Thread {
    String source, destination;

    public DownloadTempFile(String source, String destination) {
        this.source = source;
        this.destination = destination;
    }

    public void run() {
        OutputStream output = null;

        try {
            File local = new File(destination);
            output = new FileOutputStream(local);

            ftpClient.retrieveFile(source, output);
        } catch (Exception e) {
            // TODO: handle exception
        }
    }
}

并且,此代码是调用上层方法

String tempPath = mSDpath + "/mgtec/temp";
File d = new File(tempPath);

if (d.isDirectory()) {
    String tempFile = tempPath + "/tmp" + position + ".mp3";
    NativeMusicAppActivity.mConnector.downloadFile(mAdapter
            .getItem(position).toString(), tempFile);
} else {
    if (d.mkdirs()) {
        String tempFile = tempPath + "/tmp" + position + ".mp3";
        NativeMusicAppActivity.mConnector.downloadFile(mAdapter
                .getItem(position).toString(), tempFile);
    }
}

0 个答案:

没有答案