Java 列表<;字符串>;具有要编码为UTF-8的实体
我有一个获取regex值并添加到列表中的列表Java 列表<;字符串>;具有要编码为UTF-8的实体,java,utf-8,Java,Utf 8,我有一个获取regex值并添加到列表中的列表 private static List<String> listaOfQuestion(Scanner sc, List<File> listaQuestion) { List<String> question = new ArrayList<String>(); for (File input1 : listaQuestion) { try {
private static List<String> listaOfQuestion(Scanner sc, List<File> listaQuestion) {
List<String> question = new ArrayList<String>();
for (File input1 : listaQuestion) {
try {
sc = new Scanner(input1);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
while (sc.hasNextLine()) {
Scanner s = new Scanner(sc.nextLine());
while (s.hasNext()) {
String words = s.nextLine();
try {
question.add(getTagValuesQ(words).toString());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
return question;
}
我尝试使用Apache Common Lang并解决了这个问题:
String s = "Bielańska Wyziński Wciślik";
String decoded = org.apache.commons.lang3.StringEscapeUtils.unescapeHtml4(s);
System.out.println(decoded);
输出:
Bielańska Wyziński Wciślik
您想在哪里进行编码?我看不到在您的代码中使用它的任何示例。还有另一个Scanner构造函数:
公共Scanner(文件源,字符串charsetName)
,您可以在其中指定一个字符集。@Berger,这将是解码,但这是对OP含义的最佳猜测+1担心我的同事来拜访我,我编辑了我的问题真的很抱歉。Berger我使用这样的扫描器进行(File input1:listaQuestion){try{sc=new Scanner(input1,“UTF-8”);}catch(FileNotFoundException e){e.printStackTrace();}但它不起作用。我相信你的解决方案是好的,但我认为我试图以错误的方式来做这件事。
Bielańska Wyziński Wciślik