gpt4 book ai didi

java - 如何修改这段代码语句?

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

我确实需要你的帮助。

我有这个代码:

File f1 = openFile("Choose file one",
JFileChooser.OPEN_DIALOG);
if (f1 == null)
return;
File f2 = openFile("Choose file two",
JFileChooser.OPEN_DIALOG);
if (f2 == null)
return;

File f3 = openFile("Choose destination",
JFileChooser.SAVE_DIALOG);
if (f3 == null)
return;
JOptionPane.showMessageDialog(this, "Files are now joined in"
+ f3.getName());

我想摆脱这个:

File f3 = openFile("Choose destination",
JFileChooser.SAVE_DIALOG);
if (f3 == null)
return;

并使用以下代码语句,这样,但不幸的是我收到错误..!

OptionPane.showMessageDialog(this, "Files are now joined in"
+ f1.getName() + f2.getName());

如何解决这个问题?

最佳答案

如果您想添加文件名,则需要先将名称与扩展名分开。使用“lastIndexOf”方法查找“.”和 substring` 仅获取名称部分:

    ...
if (f2 == null)
return;

String newName = fileName(f1) + "+" + f2.getName(); // assuming extension of f2
// or newName = fileName(f1) + "+" + fileName(f2) + ".wav";
File f3 = new File(newName);
...

private static String fileName(File file) {
String name = file.getName();
int index = name.lastIndexOf('.');
if (index != -1) {
name = name.substring(0, index);
}
return name;
}

类似于获取扩展名 (name.substring(index+1)) 并检查两个扩展名是否相等(如果需要)。

英语不是我的第一语言(也不是第二语言),欢迎更正

编辑
但我不相信仅仅加入两个 WAV 就能产生一个有效的 WAV。我怀疑您需要从第二个 WAV 中删除 header 并实现第一个......

关于java - 如何修改这段代码语句?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3193785/

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