首页 > 解决方案 > java.nio.file.AccessDeniedException 到 ~/AppData\Local\Temp\unlink-test12695598880278433589.tmp 文件 bt-cli api

问题描述

想通过 bt-cli 下载种子。我尝试将 bt-cli 作为 bt parent 的模块启动并将 bt-cli-demo 作为项目启动,但我总是将 java.nio.file.AccessDeniedException 获取到临时文件。

我通过 Intellij Idea 和 shell 尝试过,一直都是同样的问题。

还尝试使用 -f 和 -m 键下载(链接到项目和键描述https://github.com/atomashpolskiy/bt

我总是遇到同样的异常: 异常屏幕

也许我必须更改临时文件的文件夹,但我不知道该怎么做

代码:

public static void main(String[] args) throws IOException {
    Options options;
    try {
        options = Options.parse(args);
    } catch (OptionException e) {
        Options.printHelp(System.out);
        return;
    }

    configureLogging(options.getLogLevel());
    configureSecurity();
    registerLog4jShutdownHook();

    CliClient client = new CliClient(options);
    client.start();
}

我从 shell 获得的所有参数,api 解析它并根据收入参数创建配置。然后开始。

外壳参数:

    static {
    parser = new OptionParser() {
        {
            acceptsAll(Arrays.asList("?", "h", "help")).isForHelp();
        }
    };
    metainfoFileOptionSpec = parser.acceptsAll(Arrays.asList("f", "file"), "Torrent metainfo file")
            .withRequiredArg().ofType(File.class);

    magnetUriOptionSpec = parser.acceptsAll(Arrays.asList("m", "magnet"), "Magnet URI")
            .withRequiredArg().ofType(String.class);

    targetDirectoryOptionSpec = parser.acceptsAll(Arrays.asList("d", "dir"), "Target download location")
            .withRequiredArg().ofType(File.class)
            .required();

    shouldSeedOptionSpec = parser.acceptsAll(Arrays.asList("s", "seed"), "Continue to seed when download is complete");

    sequentialOptionSpec = parser.acceptsAll(Arrays.asList("S", "sequential"), "Download sequentially");

    enforceEncryptionOptionSpec = parser.acceptsAll(Arrays.asList("e", "encrypted"), "Enforce encryption for all connections");

    verboseOptionSpec = parser.acceptsAll(Arrays.asList("v", "verbose"), "Enable more verbose logging");

    traceOptionSpec = parser.accepts("trace", "Enable trace logging");

    inetAddressOptionSpec = parser.acceptsAll(Arrays.asList("i", "inetaddr"), "Use specific network address (possible values include IP address literal or hostname)")
            .withRequiredArg().ofType(String.class);

    torrentPortOptionSpec = parser.acceptsAll(Arrays.asList("p", "port"), "Listen on specific port for incoming connections")
            .withRequiredArg().ofType(Integer.class);

    dhtPortOptionSpec = parser.accepts("dhtport", "Listen on specific port for DHT messages")
            .withRequiredArg().ofType(Integer.class);

    shouldDownloadAllFiles = parser.acceptsAll(Arrays.asList("a", "all"), "Download all files (file selection will be disabled)");
}

/**
 * @throws OptionException
 */
public static Options parse(String... args) {
    OptionSet opts = parser.parse(args);

    return new Options(
            opts.valueOf(metainfoFileOptionSpec),
            opts.valueOf(magnetUriOptionSpec),
            opts.valueOf(targetDirectoryOptionSpec),
            opts.has(shouldSeedOptionSpec),
            opts.has(sequentialOptionSpec),
            opts.has(enforceEncryptionOptionSpec),
            opts.has(verboseOptionSpec),
            opts.has(traceOptionSpec),
            opts.valueOf(inetAddressOptionSpec),
            opts.valueOf(torrentPortOptionSpec),
            opts.valueOf(dhtPortOptionSpec),
            opts.has(shouldDownloadAllFiles));
}

标签: javaexceptionaccess-deniedtemptorrent

解决方案


AccessDeniedException 可能意味着很多事情。文档说: “文件系统操作被拒绝,通常是由于文件权限或其他访问检查”,我会注意“其他”这个词。


推荐阅读