如何使用波兰语字母从String
或JTextField
获取JTextArea
?
当我使用myTxtArea.getText()
时,在JTextArea
ĄĆĘŁŃÓŚŹŻąćęłńóśźż
我得到?????Ó????????ó???
时,它只识别JTextField
。
来自JTextArea
和import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class MyAppCreateAcc {
public static void main(String[] args) throws IOException {
AppGUI ag = new AppGUI();
}
public MyAppCreateAcc() throws IOException {
String group = AppGUI.getGroup().getText();
String[] lines = AppGUI.getNote().getText().split("\\n");
BufferedWriter w = new BufferedWriter(new FileWriter(
"zaloz_konta.cmd"));
w.write("mode con codepage select=1250");
w.newLine();
for (int j = 0; j < lines.length; j++) {
/*
* delete more than one space between words and from the full name
* create a short one first letter of name and surname after all
* lowercase like on example: John Smith = jsmith
*/
if (lines[j] == null || lines[j].equals("")) {
// if there is a gap between the names do nothing
} else {
lines[j] = lines[j].trim().replaceAll(" +", " ");
Pattern pattern = Pattern.compile("\\s([A-Za-z]+)");
Matcher matcher = pattern.matcher(lines[j]);
String shortName = "";
if (matcher.find()) {
shortName = (lines[j].charAt(0) + matcher.group(1))
.toLowerCase();
}
w.write("call konto.cmd " + shortName + " \"" + lines[j]
+ "\" 123 " + "\"" + group + "\"");
w.newLine();
}
}
w.close();
}
}
的文字将保存在* .txt文件中
这是我的代码:
String[] lines = AppGUI.getNote().getText().split("\\n");
我想从以下地址获得波兰语字母:
{{1}}
答案 0 :(得分:2)
您想使用 UTF-8 编码。试一试
String s = new String(AppGUI.getNote().getText().getBytes(), "UTF-8");
String[] lines = s.split("\\n");
答案 1 :(得分:2)
JTextComponent.write()输出到FileIO
JTextComponent.read()用于从FileIO加载数据
默认情况下接受分隔符和文件编码页面
答案 2 :(得分:1)
我扩展了我的pattern
,它也有所帮助:
lines[j] = lines[j].trim().replaceAll(" +", " ");
Pattern pattern = Pattern.compile("\\s([A-Za-ząćęłńóśźżĄĘŁĆŃÓŚŹŻ]+)");
Matcher matcher = pattern.matcher(lines[j]);