Java 与Trad(字符串语言、字符串字)类似的Trad函数
我正在编写一个函数,当你点击“FR”按钮时,它将翻译所有的jlabel法语文本,当你点击“En”英语文本时 input.txtJava 与Trad(字符串语言、字符串字)类似的Trad函数,java,split,Java,Split,我正在编写一个函数,当你点击“FR”按钮时,它将翻译所有的jlabel法语文本,当你点击“En”英语文本时 input.txt Bon de Commande;Order Form S'identifier;Login Entrez votre identifiant;Enter Username Entrez votre mot de passe;Enter Password Connexion;Connection Bienvenue;Welcome java pu
Bon de Commande;Order Form
S'identifier;Login
Entrez votre identifiant;Enter Username
Entrez votre mot de passe;Enter Password
Connexion;Connection
Bienvenue;Welcome
java
public static String getTraduction(String language, String word) throws IOException {
String delim = ";";
String line = null;
int size = getNbrLigne(PathLangue);
String[][] info = new String[size][0]; //String[FR][EN][NL]
String[] temp;
int a = 0;
int b = 0;
Scanner scanner = new Scanner(new File(PathLangue));
while (scanner.hasNextLine()) {
line = scanner.nextLine();
temp = line.split(delim);
System.out.println("temp : " + line);
info[b][a] = temp[a]; //info[0][0] -> FR
info[b][a] = temp[a+1]; //info[0][1] -> EN
//info[b][a] = temp[a+2]; // info[0][2] -> NL
System.out.println("FR : "+temp[a]+" EN : "+temp[a+1]);
if (temp[a].equals(word) == true){
if (language.equals("FR")) {
(info[b][a]) = temp[a];
break;
}
if (language.equals("EN")) {
(info[b][a+1]) = temp[a+1];
break;
}
/*if (langue.equals("NL")) {
(info[b][a+2]) = temp[a+2];
break;
}*/
}
b++;
}
scanner.close();
return info[b][a];
}
此代码的问题是,当我进行拆分时,我得到:
线程“main”java.lang.ArrayIndexOutOfBoundsException中出现异常:0
第一个sysout工作,但第二个不工作,因为错误是在我执行拆分时生成的:/
在我的最终版本中,我想集成FR、EN、NL(荷兰)、DE(荷兰语)和PL(波兰语)
有人能帮忙吗?这一行有问题:
String[][] info = new String[size][0]
第二个维度是空的,因此当您访问info[b][a]
时,您将得到异常,因为第二个维度总是超出范围
您需要做的是使用第二维度所需的大小初始化数组,例如:
String[][] info = new String[size][2]; // As in your case you access indicies 0 and 1 in the 2nd dimension
这一行的问题在于:
String[][] info = new String[size][0]
第二个维度是空的,因此当您访问info[b][a]
时,您将得到异常,因为第二个维度总是超出范围
您需要做的是使用第二维度所需的大小初始化数组,例如:
String[][] info = new String[size][2]; // As in your case you access indicies 0 and 1 in the 2nd dimension
注:在英语中,“traduction”是“translation”;)Encore un faux ami…
DE
是德语,荷兰语是荷兰的语言。另外,看看这个图书馆,它可以帮助你避免一遍又一遍地写同样的东西::p du moment que les gens d'ici compensent c'est l'essentielNote:在英语中,“traduction”是“translation”;)Encore un faux ami…DE
是德语,荷兰语是荷兰的语言。另外,看看这个图书馆,它可以帮助你不必一次又一次地写同样的东西::p du moment que les gens d'ici compensent c'est l'Essentieltanks它是:)谢谢它是:)