Re: change ISO8859-1 to GB2312
On 5=E6=9C=8820=E6=97=A5, =E4=B8=8A=E5=8D=8811=E6=99=8258=E5=88=86, Lew <no=
....@lewscanon.com> wrote:
moonhkt wrote:
Change your code as below. My test file can conv to UTF-8, view in
Reflection UTF-8 Emulation, the font is ok.
What is "Reflection UTF-8"?
Not a bad job there, but I have to wonder why you ruined the indentation =
and
still are flouting the naming conventions. Code should be readable.
Also, it is exceedingly bad that you eliminated logging. You should=
keep the
logging. Switch to java.util.logging if you don't like log4j or don=
't care to
add the JAR, but for Pete's sake keep the logging. Yikes.
Here's a pop quiz for you - given that few code examples I've seen use th=
e
idiom I did of a separate try block for opening the Reader and Writer fro=
m the
one for using them, why do you think I bothered?
Is it better or worse than the common idiom, or simply a matter of style =
and
more power to you for whichever?
View in IE the font is ok.
temp.txt file
| 10 TEST1 |=E6=B5=8B=E8=AF=951
| =
|
| 11 TEST2 |=E6=B5=8B=E8=AF=952
| =
|
| 12 TEST3 |=E6=B5=8B=E8=AF=953
| =
|
| 13 TEST4 |=E6=B5=8B=E8=AF=954
| =
|
| 14 TEST5 |=E6=B5=8B=E8=AF=955
| =
|
import java.io.*;
public class conv_ig
{
public static void main( String[] args )
{
new conv_ig().recode();
}
public void recode()
{
final BufferedReader rin;
final BufferedWriter owt;
try
{
rin = new BufferedReader( new InputStream=
Reader(
/* getClass().getResourceAsStream( "t=
emp.txt" ),
"ISO-8859-1" ));
owt = new BufferedWriter( new Outp=
utStreamWriter(System.out,
"GB2312" ));
*/
getClass().getResourceAsStream( "temp.txt" =
),"GB2312" ));
owt = new BufferedWriter( new OutputStrea=
mWriter(
System.out, "UTF-8" ));
}
catch ( IOException exc )
{
/* logger.error( exc ); */
return;
}
try
{
for ( String str; (str = rin.readLine()) =
!= null; )
{
owt.write( str );
owt.newLine();
}
owt.flush();
}
catch ( IOException exc )
{
/* logger.error( exc ); */
}
finally
{
try
{
rin.close();
owt.close();
}
catch ( IOException exc )
{
/* logger.error( exc ); */
}
}
}
}
--
Lew
Sorry about this. This is dirty method to test the code. Reflection
is Telnet software using UTF-8 Emulation to check the the string
encoding.
I will check How to using java.util.logging .
Can you give some example where "ruined the indentation " ? and what
about the the naming conventions ?