我在 file.csv 中有這一行“????????”,它被編碼為 ANSI(如 Notepad++ 顯示)。如何在像 CcEeLzzl 這樣的控制臺中正確顯示這一行?為了刪除重音,我使用 apache 中的 StringUtils.stripAccents(myLine) 但仍然得到“??Ee????” FileReader fr = null; try { String sCurrentLine; br = new BufferedReader(new FileReader(fileName2)); while ((sCurrentLine = StringUtils.stripAccents(br.readLine())) != null) { System.out.println(StringUtils.stripAccents(sCurrentLine)); } } catch (IOException e) { e.printStackTrace(); } finally { try { if (br != null) br.close(); if (fr != null) fr.close(); } catch (IOException ex) { ex.printStackTrace(); } }```I want in COnsole this "CcEeLzzl", not that "????????". Please help me.
1 回答

BIG陽
TA貢獻1859條經驗 獲得超6個贊
看起來您想要應用從波蘭語字母到 ascii 的自定義映射,這超出了stripAccents. 也許您必須自己定義它,例如如下所示(僅顯示“?”和“?”)。
劇透:不,你不必這樣做。Windows 編碼上的 ansi 是罪魁禍首。通過正確的解碼StringUtils.stripAccents工作得很好??丛u論。但如果您離開 stripAccents 的域名...
public void Ll() {
Map<String, String> map = new HashMap<>();
map.put("?", "L");
map.put("?", "l");
System.out.println(Arrays.stream("?a?a?a?a".split("(?!^)"))
.map(c -> {
String letter = map.get(c);
return letter == null ? c : letter;
})
.collect(Collectors.joining("")));
}
添加回答
舉報
0/150
提交
取消