I am writing a file in java with BufferedWriter. Here is my code -
public static void main(String[] args) {
try(BufferedWriter writer = Files.newBufferedWriter(filePath, Charset.forName("CP1252"))) {
while (thereIsContentToWrite){
writer.write(content);
}
}catch (CharacterCodingException ce){
//get content of writer's current buffer (java.io.BufferedWriter.cb)
}catch (IOException e) {
e.printStackTrace();
}
}
I want to report out the content of the current buffer of writer as it contains the "Unmappable character" as per cp1252. Currently, we are trying to maintain another buffer to hold the content but I would like to know whether there is a better approach to achieve the same.