0

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

这是代码

/**
 * 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);
    }
}
4

0 回答 0