3

如何String从波兰字母中获取JTextFieldJTextArea使用波兰字母?当我使用myTxtArea.getText()并且在我的JTextArea我得到ĄĆĘŁŃÓŚŹŻąćęłńóśźż它时,它只识别?????Ó????????ó???.

JTextField两者的文本都JTextArea将保存在 *.txt 文件中

那是我的代码:

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();
}

}

我想从以下地址获取波兰语信件:

String[] lines = AppGUI.getNote().getText().split("\\n");

4

3 回答 3

2

您想使用UTF-8编码。试试看

 String s = new String(AppGUI.getNote().getText().getBytes(), "UTF-8");
 String[] lines = s.split("\\n");     
于 2013-03-06T11:55:28.827 回答
2

JTextCompoents使用

默认情况下接受分隔符和文件编码页面

于 2013-03-06T12:46:12.590 回答
1

我扩展了我的pattern,它也有帮助:

lines[j] = lines[j].trim().replaceAll(" +", " ");
Pattern pattern = Pattern.compile("\\s([A-Za-ząćęłńóśźżĄĘŁĆŃÓŚŹŻ]+)");
Matcher matcher = pattern.matcher(lines[j]);
于 2013-03-06T13:36:02.630 回答