Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > [sun java] conver charset for string

Reply
Thread Tools

[sun java] conver charset for string

 
 
Rafal \(sxat\)
Guest
Posts: n/a
 
      04-14-2007
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







 
Reply With Quote
 
 
 
 
Joshua Cranmer
Guest
Posts: n/a
 
      04-15-2007
Rafal (sxat) wrote:
> 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


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.)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
javascript charset <> page charset optimistx Javascript 2 08-15-2008 12:42 PM
Conver Time to Seconds vunet.us@gmail.com Javascript 8 01-13-2007 12:26 AM
can '1' be conver to true ,and the '0' conver to false ? Kylin ASP .Net 2 06-02-2005 03:08 PM
I'd like to conver long value to IP address, which fuction do I have to use? somez72 Java 4 05-03-2004 09:27 PM
how i conver a string to number with asp? John Muņoz ASP General 1 11-20-2003 08:35 PM



Advertisments