Win a copy of Machine Learning with R: Expert techniques for predictive modeling this week in the Artificial Intelligence and Machine Learning 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
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

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.
 
Aaaaaand ... we're on the march. Stylin. Get with it tiny ad.
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!