0

我正在寻找一种以编程方式创建新配置文件的方法,但找不到任何特定的 API 或任何简单的解决方案,例如在特定文件夹中创建特定文件等。有人遇到过这个问题吗?

4

1 回答 1

0

像这样的东西:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class NewFirefoxProfilesCreator {
    public static void main(String[] args) {
        int end =100;
        int start = 1;
        for (int i=start; i<=end; i++) {
            try {

                Process process = Runtime.getRuntime().exec("\"C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe\" -no-remote -CreateProfile rnn"+i);

                StringBuilder output = new StringBuilder();

                BufferedReader reader = new BufferedReader(
                        new InputStreamReader(process.getInputStream()));

                String line;
                while ((line = reader.readLine()) != null) {
                    output.append(line + "\n");
                }

                int exitVal = process.waitFor();
                if (exitVal == 0) {
                    System.out.println("Success!");
                    System.out.println(output);
                } else {
                    //abnormal...
                }

            } catch (IOException e) {
                e.printStackTrace();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

循环创建 100 个 Firefox 配置文件。

于 2020-07-03T16:31:27.293 回答