我在一個對象內部有正常的String屬性,包含重音字符。 如果我調試軟件(使用Netbeans),到變量面板我會看到正確的方式將字符串:在Java中輸出和preg到Unicode字符串
但是,當我要打印出與System.out的變量。的println我會看到奇怪的事情:
正如你可以看到每一個「A」變成了「一「」等等,而這將導致一個錯誤的字符數,即使在匹配器上的字符串。
我該如何解決這個問題?我需要重音字符,讓正確的字符數和使用匹配器。 我嘗試了很多方法,但不會去工作,肯定我錯過了一些東西。
在此先感謝。
EDIT
再次編輯
這是代碼:
public class TextLine {
public List<TextPosition> textPositions = null;
public String text = "";
}
public class myStripper extends PDFTextStripper {
public ArrayList<TextLine> lines = null;
boolean startOfLine = true;
public myStripper() throws IOException
{
}
private void newLine() {
startOfLine = true;
}
@Override
protected void startPage(PDPage page) throws IOException
{
newLine();
super.startPage(page);
}
@Override
protected void writeLineSeparator() throws IOException
{
newLine();
super.writeLineSeparator();
}
@Override
public String getText(PDDocument doc) throws IOException
{
lines = new ArrayList<TextLine>();
return super.getText(doc);
}
@Override
protected void writeWordSeparator() throws IOException
{
TextLine tmpline = null;
tmpline = lines.get(lines.size() - 1);
tmpline.text += getWordSeparator();
tmpline.textPositions.add(null);
super.writeWordSeparator();
}
@Override
protected void writeString(String text, List<TextPosition> textPositions) throws IOException
{
TextLine tmpline = null;
if (startOfLine) {
tmpline = new TextLine();
tmpline.text = text;
tmpline.textPositions = textPositions;
lines.add(tmpline);
} else {
tmpline = lines.get(lines.size() - 1);
tmpline.text += text;
tmpline.textPositions.addAll(textPositions);
}
if (startOfLine) {
startOfLine = false;
}
super.writeString(text, textPositions);
}
}
這不僅僅是控制檯中的顯示問題嗎?字符串仍然應該包含正確的字符。 –
可能重複[如何爲我的JVM設置默認語言環境?](https://stackoverflow.com/questions/8809098/how-do-i-set-the-default-locale-for-my-jvm) – Colonder
不,因爲即使我做了一個字符串。長度計數是錯誤的(正在計算額外的口音) –