aspose file tools
The moose likes Java in General and the fly likes Set an encoding scheme for InputStreamReader and ByteArrayOutputScream !!! Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Set an encoding scheme for InputStreamReader and ByteArrayOutputScream !!!" Watch "Set an encoding scheme for InputStreamReader and ByteArrayOutputScream !!!" New topic
Author

Set an encoding scheme for InputStreamReader and ByteArrayOutputScream !!!

kathir je
Greenhorn

Joined: Jun 07, 2006
Posts: 12

Hi,

I would like to know how we can set the encoding scheme for InputStreamReader and ByteArrayOutputScream

I've files where few sentences with the character à

I'm using the below code snippet to convert the file input stream to bytes array

ByteArrayOutputStream stream = new ByteArrayOutputStream();
BufferedReader fileReader = new BufferedReader(new InputStreamReader(inStream));
String line;
while ((line = fileReader.readLine()) != null) {
stream.write(line.getBytes());
stream.write((byte) '\n');
}
return stream.toByteArray();

Later after doing some operations i'm converting the bytes to string as follows

StringBuilder buf = new StringBuilder();
for (int i = 0; i < inFile.length; i++) {
byte b = inFile;
buf.append((char) b);
}
String s = buf.toString().trim();

The final converted string doesn't have the above latin character à

Is there is any way to get the string content along with the character à?

Thanks,
Kathir
James Boswell
Ranch Hand

Joined: Nov 09, 2011
Posts: 344
How about


Although personally, I don't think using the style of chaining method calls on same line.
 
 
subject: Set an encoding scheme for InputStreamReader and ByteArrayOutputScream !!!
 
Threads others viewed
java io question, conceptual query
IO Question
can't able to retrive the string from url
IO Question from javacaps
cant get the string from url
IntelliJ Java IDE