0

我可以使用robot类从我的应用程序下载一个 zip 文件,但是如何将该 zip 保存到特定文件夹中?

请帮助我。

4

1 回答 1

0

The simplest answer for me to give would be to use java to copy the download to somewhere else using Java. (If you don't know how to do that, there are plenty of explanations here on SO).

However, I don't know what your robot class is doing, nor what browser you have. If you are using the robot class to press OK, you can probably also use it to type in the path.

However, if you are using FirefoxDriver, my favorite way is to enable automatic downloading. When you create your instance of FirefoxDriver, create a FirefoxProfile to pass in with the following settings:

FirefoxProfile profile = new FirefoxProfile();

            //Enable automatic downloading
            profile.setPreference("browser.download.folderList",2);
            profile.setPreference("browser.download.manager.showWhenStarting",false);;
            profile.setPreference("browser.download.dir","SOMEFOLDERGOESHERE");
            profile.setPreference("browser.helperApps.neverAsk.saveToDisk","application/octet-stream");
FirefoxDriver driver = new FirefoxDriver(profile);

You will need to replace application/octet-stream with the MIME type of download you are trying to download.

This will allow you to automatically download a file to a specific folder.

于 2013-08-02T14:38:48.047 回答