I am trying to read from a pdf file using file streams and I want to write it to a writer in cp1252 encodeded format. Following is the code:
byte buf[] = new byte[8192];
InputStream is = new FileInputStream(f);
ByteArrayOutputStream oos = new ByteArrayOutputStream();
int c=0;
while ((c = is.read(buf)) != -1) {
oos.write(buf, 0, c);
}
byte out[] = oos.toByteArray();
String str = oos.toString(out,"UTF-8");
char[] ch = str.toCharArray();
writer.write(ch);
is.close();
oos.close();
But the output is erroneous as the text is not readable(not properly converted). How do I fix this ?