您好,我在这个简单的转换任务中遇到了一些问题。下面是我的代码(粗略但不那么复杂):
FileInputStream fis = new FileInputStream ("file");
BufferedReader reader = new BufferedReader(new InputStreamReader(fis,"CP1250"));
try {
StringBuilder sb = new StringBuilder();
String line = null;
try {
line = reader.readLine();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
while (line != null) {
sb.append(line);
if(line.contains(" "))
sb.append(System.lineSeparator());
try {
line = reader.readLine();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
String everything = sb.toString();
System.out.println(everything);
PrintWriter writer = null;
try {
writer = new PrintWriter("clean", "UTF-8");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
writer.println(everything);
writer.close();
}
finally {
try {
reader.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
但是我得到与输入相同的输出,具有相同的编码格式。你看到无论如何都能提供帮助吗?