Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Set an encoding scheme for InputStreamReader and ByteArrayOutputScream !!!

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
Bartender
Posts: 1051
5
Hibernate Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about


Although personally, I don't think using the style of chaining method calls on same line.
 
Live a little! The night is young! And we have umbrellas in our drinks! This umbrella has a tiny ad:
Try Free Java/.NET Libraries for Word Excel PowerPoint and PDF
htttp://www.e-iceblue.com/free-apis.html
    Bookmark Topic Watch Topic
  • New Topic