gpt4 book ai didi

java - 将 jFileChooser 中选择的文件设置为字符串?

转载 作者:行者123 更新时间:2023-12-01 12:03:44 24 4
gpt4 key购买 nike

我想将 jFileChooser 中选择的文件设置为 stringbuilder 段的字符串,但是采用特定的模式。即

        {
sb.append(" -file").append(mods);
}

“mods”是文件,每个文件之间是一个“-file”,例如,如果我选择 file1.wad、file2.wad 和 file3.pk3,则程序所需的输出将是

-file file1.wad -file file2.wad -file file3.pk3

我该怎么做?

编辑这是我的更多代码。 Paco Abato 建议的代码到底会去哪里?因为在代码的底部它会吐出大量错误。

private void RunGameButtonActionPerformed(java.awt.event.ActionEvent evt) {                                              
String PlayerCount = PlayerCountHere.getText();
String HostIP = HostIPHere.getText();
//String MapWarp = MapWarpBox.getName();
try
{
//Basic game launching command.
StringBuilder sb = new StringBuilder("cmd.exe /C start C:\\mygame\\game.exe");
if(NoMonstersBox.isSelected())
{
//Add the No Monsters Flag
sb.append(" -nomonsters");
}
if(CheatsBox.isSelected())
{
//Add the Cheats Flag
sb.append(" +SV_CHEATS 1");
}
if(Netmode0Button.isSelected())
{
//Add Netmode 0 Flag
sb.append(" -netmode 0");
}
if(Netmode1Button.isSelected())
{
//Add Netmode 1 Flag
sb.append(" -netmode 1");
}
if(DeathmatchButton.isSelected())
{
//Add the Deathmatch Flag
sb.append(" -deathmatch");
}
if(CoopButton.isSelected())
{
//Add the Co-op Flag
sb.append(" -coop");
}
if(Skill1Button.isSelected())
{
//Add the Skill 1 Flag
sb.append(" -skill 1");
}
if(Skill2Button.isSelected())
{
//Add the Skill 2 Flag
sb.append(" -skill 2");
}
if(Skill3Button.isSelected())
{
//Add the Skill 3 Flag
sb.append(" -skill 3");
}
if(Skill4Button.isSelected())
{
//Add the Skill 4 Flag
sb.append(" -skill 4");
}
if(Skill5Button.isSelected())
{
//Add the Skill 5 Flag
sb.append(" -skill 5");
}
if(HostButton.isSelected())
{
//Add the Host Flag and add the Player Count from the box
sb.append(" -host ").append(PlayerCount);
}
if(JoinButton.isSelected())
{
//Add the Join Flag and add the Host IP from the box
sb.append(" -join ").append(HostIP);
}
//Launch the game
Process process = Runtime.getRuntime().exec(sb.toString());
}
catch(IOException e)
{
//Log Error
}
}

最佳答案

很简单:

for (File file : selectedFiles) {
sb.append(" -file ").append(file.getName());
}

关于java - 将 jFileChooser 中选择的文件设置为字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27821852/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com