Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/394.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何指定图标的跨平台路径?_Java_Path_Icons_Cross Platform - Fatal编程技术网

Java 如何指定图标的跨平台路径?

Java 如何指定图标的跨平台路径?,java,path,icons,cross-platform,Java,Path,Icons,Cross Platform,我在Java中完全是零,我只需要编辑部分源代码,我被卡住了 因此,我有以下代码: package net.technicpack.legacywrapper; import com.beust.jcommander.Parameter; import com.beust.jcommander.internal.Lists; import java.io.File; import java.io.IOException; import java.net.URLDecoder; import j

我在Java中完全是零,我只需要编辑部分源代码,我被卡住了

因此,我有以下代码:

package net.technicpack.legacywrapper;

import com.beust.jcommander.Parameter;
import com.beust.jcommander.internal.Lists;

import java.io.File;
import java.io.IOException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

public final class StartupParameters {
    @SuppressWarnings("unused")
    private final String[] args;
    public StartupParameters(String[] args) {
        this.args = args;
        auth_player_name = args[0];
        auth_session = args[1];
    }
    @Parameter
    private List<String> parameters = Lists.newArrayList();

    private String auth_player_name;

    private String auth_session;

    @Parameter(names = {"--gameDir"}, description = "Pack directory")
    private String gameDir;

    @Parameter(names = {"--assetsDir"}, description = "Assets directory")
    private String assetsDir;

    @Parameter(names = {"--width"}, description = "Sets the width of the minecraft window to be fixed to this.")
    private int width = -1;

    @Parameter(names = {"--height"}, description = "Sets the height of the minecraft window to be fixed to this.")
    private int height = -1;

    @Parameter(names = {"--title"}, description = "The title bar text for the Minecraft frame.")
    private String title = "Minecraft";

    @Parameter(names = {"--icon"}, description = "The title bar icon for the Minecraft frame.")
    private String icon = "path to .ico";

    public List<String> getParameters() {
        return parameters;
    }

    public String getAuthPlayerName() { return auth_player_name; }
    public String getAuthSession() { return auth_session; }
    public String getGameDirectory() { return gameDir; }
    public String getAssetsDirectory() { return assetsDir; }
    public int getWidth() { return width; }
    public int getHeight() { return height; }
    public String getTitle() { return title; }
    public String getIconPath() { return icon; }
}
我需要在这里指定图标的路径,而不是“path to.ico”,但我不知道如何指定。此路径必须是跨平台的,以便所有内容都能在Windows和Linux上运行。例如,图标将位于:

窗口: C:/Users/Some user/AppData/Roaming/.gamefolder/res/icon.png

或Linux: /home/someuser/.gamefolder/res/icon.png


如何在代码中指定这些路径?另外,我认为将图标放在JAR文件中会更容易,这样就可以从中读取它。但话说回来,我不知道该怎么做。请提供帮助。

您可以从构建相对于
System.getProperty(“user.home”)的路径开始。
;但是对于命令行参数,它可能会接受传递的任何值。您能告诉我如何在我的情况下使用它吗?我真的不明白它需要写在哪里才能工作。。。
@Parameter(names = {"--icon"}, description = "The title bar icon for the Minecraft frame.")
private String icon = "path to .ico";