Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2007

Tip: Looking for answers? Try searching our database.

[sun java] conver charset for string

Thread view: 
Rafal (sxat) - 14 Apr 2007 22:07 GMT
Hello

how change charset for this string from cp1250 (Windows) to UTF-8

all Program in java is default running in UTF-8

     File f = new File("C:/myfile.txt);
     FileReader rd = new FileReader(f);
    System.out.println("GET - encoding: " + rd.getEncoding()); /* this is
always utf-8 why?*/
     char[] buf = new char[(int)f.length()];
     rd.read(buf);
     return new String(buf).replaceAll("[\n\r]*", "");

myfile is charset cp1250
how change String from cp1250 to utf 8 ?

regards
Rafal
Joshua Cranmer - 15 Apr 2007 20:03 GMT
> Hello
>
[quoted text clipped - 15 lines]
> regards
> Rafal

From the API for java.io.FileReader:
The constructors of this class assume that the default character
encoding and the default byte-buffer size are appropriate. To specify
these values yourself, construct an InputStreamReader on a FileInputStream.

So your second line would be:
InputStreamReader rd = new InputStreamReader(new FileInputStream(f),
"cp1250");

("cp1250" or "Cp1250"? I don't actually know.)


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.