• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to hold the original charset of a String when output it to a file through java.io

 
Shannon Lee
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
As we know, java VM will change the String object's origenal charSet (or encoding) to the local platform's default charset when we output the String to a physical file through java.io.Writer or java.io.outputStream. for example, the String are encoding in UTF8, and be send to a server which default charset is not UTF8.
So, what can be done to disable the JVM to do that, let the system record the String to a file in it's origenal charSet as it been stored in local mermory.
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ShannonLee-
Welcome to the JavaRanch! Please adjust your displayed name to meet the JavaRanch Naming Policy. You can do so here.
Thanks! and again, Welcome to the Ranch!
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not entirely sure what you're trying to do, but it's possible to control the encoding used when reading and writing from streams, using the InputStreamReader and OutputStreamWriter classes. These allow you to specify whatever encoding you want to. Antime you are manipulating character data and sending it from one platform to another (where default encoding may be different) it is a good idea to decide what encoding you want to use, and make sure you only read & write using that encoding.
 
Shannon Lee
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you Jim
but I really want is record the same ascii data of a String in memory to, for example, the file system that OS-related. If java.io provid any api to do this without specify the encoding of the String ? It seems the encoding will be changed to local platform's default automatically by JVM when I put the string to a IO stream.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!