Using FileReader/Writer with Asian Characters - can you spot my problem?

Hi,
I can read in and write out one byte at a time with Asian characters, but if I try to do it one line at a time the Asian output is garbage. I will list both little programs here, and hopefully someone can educate me on my problem.
+++1st, *this {color:#339966}works fine{color} with Asian characters:*+
+{color:#000000}import java.io.*;*{color}+
{color:#000000}class copybyte
public static void main (String args[]) throws IOException
if (args.length != 2)
System.out.println("Usage: java copybyte srcfile dstfile");
return;
final boolean DEBUG=true; // switch for ascii display
int ch; // the buffer{color}
{color:#000000}// Create streams
FileInputStream fis = new FileInputStream (args[0]);
FileOutputStream fos = new FileOutputStream (args[1]);{color}
{color:#000000}while ((ch = fis.read()) != -1)
fos.write(ch);
if (DEBUG)
System.out.print(ch);
System.out.println(" "+Character.toString((char)ch));
fis.close(); fos.close();
}{color}
But the following code outputs Asian characters in garbage to my text file:
{color:#000000}import java.io.;
// Does not seem to handle Japanese....
class CopyLineIO
public static void main (String args[]) throws IOException
if (args.length != 2)
System.out.println("Usage: java copyline srcfile dstfile");
return;
final boolean STRIP=true; //strip blank lines from file ??
String buf,temp;
// Create streams
FileReader fr = new FileReader (args[0]);
FileWriter fw = new FileWriter (args[1]);
BufferedReader br=new BufferedReader(fr); //wrap basic object
BufferedWriter bw=new BufferedWriter(fw); //wrap basic object
while ((buf = br.readLine()) != null)
temp=buf.trim();
if ((temp.length()>0)||(!STRIP)) {bw.write(buf"\n");}
br.close(); bw.close();
fr.close(); fw.close();
Can anyone advise on what to change in CopyLineIO so that Asian characters work?{color} Thanks!
PS Sorry about the code formatting - not sure how to get it looking decent here when pasted in....
Edited by: JavaNeo on Jan 14, 2010 7:10 AM

[From the documentation|http://java.sun.com/javase/6/docs/api/java/io/FileReader.html]:
Convenience class for reading character files. 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. To post code use { code } // your code here { code } without the spaces or simple select the code and press the CODE button.
// your code here

Similar Messages

  • Hello.I can`t buy applications in my apple id.Then i buy in applications writes error contact support.Can you fix this problem?Thaks

    Hello.I can`t buy applications in my apple id.Then i buy in applications writes error contact support.Can you fix this problem?Thaks

    We are all itunes users just like you.
    You need to contact itunes support.
    http://www.apple.com/support/itunes/contact/

  • Sir you have replied for my question, and i updated my software and all those things, yet it is showing unable to connect network, but i can use internet by sim, is it the problem related with hardware? can you tell me a solution for it?

    sir you have replied for my question, and i updated my software and all those things, yet it is showing unable to connect network, but i can use internet by sim, is it the problem related with hardware? can you tell me a solution for it?

    you seem to be referring to an ongoing issue
    click here to respsond -> sir help me to enable my network connection, my iphone 4s is not connecting with any wireless connection, what i should do for enabling network connection?
    CCC

  • I've lost half of my icons such as calculator, fonts, chess, automator,ichat,ical it it saying that you can use this version with the OSX.  You have version 4.04. And, there is no way to update them.  What do you do?

    I've lost half of my icons such as calculator, fonts, chess, automator,ichat,ical it it saying that you can use this version with the OSX.  You have version 4.04. And, there is no way to update them.  What do you do?

    If I'm understanding you correctly, those apps have stopped working and you are getting a message saying that they won't work with this version of Mac OS X when you try to open them. Is that right? If so, have you moved those apps out of their original locations? That is a bad idea, as it prevents them from being properly updated. If this is what has happened, what version of the system were you running before they stopped working, and what version are you running now, after installing the update that has made them stop working?

  • Send email with Asian characters

    Hi
    Does anyone know how to send email with Asian characters? Sample code will be useful. I got ?? instead of the real characters, please help....
    Thanks in advance
    Ken

    Hello.
    How are you doing?
    Good Day.
    I think I have the concepts down some, I'm just gonna
    ask some questions for confirmation. First I'll list a
    statement then I'll as the question about the
    statement.
    If the statement is correct answer yes, on the other
    hand if the statement is false. Answer no to the
    question and explain.
    My purpose for asking you questions. Is to get a better understanding of JavaMail and to clear up any doubt. That, I may have on this subject that is related to the statements and questions.
    By having some one like you respond to my questions with answers.
    Here we go!
    The content of the Part Interface and Message class are not attributes at all.
    If this statement is correct or not correct please explian why.
    Is this statement correct?
    A DataHandler is the class called DataHandler and the
    object of the DataHandler class, which programmers
    would call the DataHandler object; which is (normally
    created by using the DataHandler class constructor). The DataHandler class, wraps the data into the DataHandler object which is called DataHandler; by you or I using the DataHandler class constructor.
    This statement is correct right?
    The DataHandler class takes the data you pass to it's
    constructor and wraps it into the DataHandler's object
    as one entity called an email message.
    Is this statement correct?
    Thanks in advance.
    Please email me as soon as possible;
    at [email protected]
    Peace out, have a good day.
    -Leroy

  • Slideshow: label with asian characters

    I just installed Fw CS3 french edition.
    When using the create sldeshow command from the menu I get 5
    tabs on the right side of the window.
    The last one appear with asian characters and a pop-up as
    well when clicking the create button.
    How to resolve it ?
    Best regards

    Hello.
    How are you doing?
    Good Day.
    I think I have the concepts down some, I'm just gonna
    ask some questions for confirmation. First I'll list a
    statement then I'll as the question about the
    statement.
    If the statement is correct answer yes, on the other
    hand if the statement is false. Answer no to the
    question and explain.
    My purpose for asking you questions. Is to get a better understanding of JavaMail and to clear up any doubt. That, I may have on this subject that is related to the statements and questions.
    By having some one like you respond to my questions with answers.
    Here we go!
    The content of the Part Interface and Message class are not attributes at all.
    If this statement is correct or not correct please explian why.
    Is this statement correct?
    A DataHandler is the class called DataHandler and the
    object of the DataHandler class, which programmers
    would call the DataHandler object; which is (normally
    created by using the DataHandler class constructor). The DataHandler class, wraps the data into the DataHandler object which is called DataHandler; by you or I using the DataHandler class constructor.
    This statement is correct right?
    The DataHandler class takes the data you pass to it's
    constructor and wraps it into the DataHandler's object
    as one entity called an email message.
    Is this statement correct?
    Thanks in advance.
    Please email me as soon as possible;
    at [email protected]
    Peace out, have a good day.
    -Leroy

  • Using a Mac with Mavericks how can i change a desktop folder' name?

    using a Mac with Mavericks how can i change a desktop folder's name?

    click on the folder, then click on the name again, you'll see the name field changes so you can rename it

  • When using the "submit by email" feature can you add 2 emails?

    When using the "submit by email" feature can you add 2 emails?

    Yes. Seperate them with semicolon (;) just like you would in a normal email client.
    Kyle

  • I was trying to make a purchase from Amazon & a return but FIREFOX would not let me open drop down boxes in the purchase & return areas. I was forced to use IE to accomplish the deed. Can you investigate the problem?

    I was trying to make a purchase from Amazon & a return but FIREFOX would not let me open drop down boxes in the areas. I was forced to use IE to accomplish the deed. Can you investigate the problem? Thanx, David Deters

    Thanks for the welcome Karsten! I’ve checked the installer disks – which appear to have all the main pieces of software, but not iDVD. If you or anyone knows where it might be hidden that would be great. Thanks for all the other info too!
    Thanks Lennart – I don’t think my computer could support iLife ’05 as it is running Mac OSX 10.3.2 and I’ve just been looking at its system requirements which state it requires 10.3.4 minimum – if you know differently, please let me know. As an alternative I have considered getting iLife ’04, but your comment about iLife ’05 being the first version to support external drives worried me (“iDVD 5 is the first iDVD version that officially supports external burners“ does this mean there is an unofficial option for iLife ‘04? Perhaps a patch similar to the one mentioned by Karsten), does that mean iLife ’04 would not support an external Lacie DVD writer?
    What is the earliest version of Toast I’d be able to use (as a money saving option!)?
    Thank you both, and apoligies for my amateurish questions…
    Kevin.

  • Since the last update of firefox, the time has been 25 to 35 seconds to enter bookmarks or even the time it takes to page down when it used to take a few seconds. can you check why it taking so long since the update on firefox.

    since the last update a few days ago of firefox, the time has been 25 to 35 seconds to enter bookmarks or even the time it takes to page down when it used to take a few seconds. can you tell me why it taking so long since the update on firefox. may another update is in order.

    I have now done pretty much every suggestion that even vaguely applies in the various helpful link provided. Thanks for the ongoing help. =)
    I have managed to get FireFox's start-up memory usage down to about 100,000K, however it appears that memory usage keeps creeping up the longer FireFox is open. (It seems to top out around 500,000K.) And I'm not talking open for many hours or days - but rather for minutes and possibly up to a couple hours. (Based on how long I've been fiddling with all this so far.)
    On the plus side, it does not appear GreaseMonkey is the culprit since with it active or disabled this memory creep still occurs. Although having GreaseMonkey enabled definitely increases the rate of memory creep. Though once it has creeped up to 150,000+K, disabling GM does not make it drop back down to the starting 100,000K.
    I should point out I run a MacBook Pro and use Bootcamp to partition the hard drive and run it as a Windows 7 PC about half the time. I am running it literally as a PC or, alternately, as a Mac depending on which hard drive I choose to load. (I'm not "windowing" it.) This problem exists regardless of whether I am using the PC or the Mac. These repairs have been made currently on the PC side, and I will attempt them all again on the Mac side. I find it odd that this enormous memory drain has occurred on 3 different computers at the same time. (The two "halves" of my home laptop as well as the PC at my work place.)

  • Unable to sync iMac address book with iPad. Can you please help?

    Unable to sync iMac address book with iPad. Can you please help?

    I have the same problem as Sheilaza but haven't been able to solve it using the advice offered.  The same problem applies to my Calendars. When I look at my iPad settings in iTunes, it says:
    Sync Contacts
    Your contacts are being synced with your iPad over the air from iCloud.
    Over-the-air sync settings can be changed on your iPad.
    and the same for Calendars.
    On the iPad, in iCloud settings, I have checked 'Contacts' and 'Calendars' as 'ON' but the Calendar remains blank and the Contacts are a very old version that was somehow created when I set up the iPad initially.
    Any ideas?
    Thanks.

  • I don't know how to setup FF to open in last session of windows wont let me save current sessions like it used to ask me fairly disappointing can you help m? Phil

    Question
    i don't know how to setup FF to open in last session of windows wont let me save current sessions like it used to ask me fairly disappointing can you help m? Phil

    ''want FF to open in last session of windows -- won't ask me if I want to save current sessions like it before''
    '''You can still have the old messages''', to make sure you get your tabs restored immediately, but with or without the messages and whichever way you respond to the message you can still get back your previous session through the History menu. (see item #31 "tabslost")
    * http://dmcritchie.mvps.org/firefox/firefox-problems.htm#tabslost
    You can make '''Firefox 6.0''' look like Firefox 3.6.*, see numbered items 1-10 in the following topic [http://dmcritchie.mvps.org/firefox/firefox-problems.htm#fx4interface Fix Firefox 4.0 toolbar user interface, problems (Make Firefox 4.0 thru 6.0, look like 3.6)]. ''Whether or not you make changes, you should be aware of what has changed and what you have to do to use changed or missing features.''
    * http://dmcritchie.mvps.org/firefox/firefox-problems.htm#fx4interface

  • I will type in google let say tree the search will click on to one of the searches and instead of tree web page showing up a ad page will come up this happens with very thing can you help.

    I will type in google let say tree the search will click on to one of the searches and instead of tree web page showing up a ad page will come up this happens with very thing can you help.

    You (or your kids) inadvertently installed adware. You do not need to download or install anything to fix it.
    Any tips on how to stop it from happening?
    Yes. To learn how to avoid it in the future read How to install adware.
    If you require them, Apple's removal instructions are linked in the Recovery Procedure near the end of that document. Read and follow them carefully. Pay particular attention to the easily overlooked passages directing you to restart your Mac when required.

  • HP 8500 printer will not print fast on firefox, but does on Safari. HP support says it is a problem with firefox. Can you help me out?

    Question
    HP 8500 printer will not print fast on firefox, but does on Safari. HP support says it is a problem with firefox. Can you help me out? edit

    Thank you for posting your list of installed Extensions. One of them might be intercepting the menu command. Since you have the Add-on Compatibility Reporter, it's possible that an older add-on that doesn't actually work well with Firefox 5 could be to blame. Could you try disabling the "HP Smart Web Printing" extension and see whether that makes any difference?
    Also, you can simulate a print button on a web site by pasting this to the location bar and pressing Enter. You also can save it as a bookmark for easier access (when scripts are saved as bookmarks, we call them bookmarklets). Hopefully you won't need it for long.
    <br>javascript:void(window.print());

  • HT5282 I my safari automatically wiped when i took update. I am using Mac 10.6.8. Can you please send me how to reinstall it. Due to this my mail email system also effected. can you please help me soon

    I my safari automatically wiped when i took update. I am using Mac 10.6.8. Can you please send me how to reinstall it. Due to this my mail email system also effected. can you please help me soon

    The reason Safari "wiped" is unknown, but try reapplying the OS X 10.6.8 Combo update here:
    Mac OS X 10.6.8 Update Combo v1.1
    Your email problems may or may not be related. A more complete explanation of the problem would help.

Maybe you are looking for

  • How to identify open sales orders by sales representative by due date. ?

    We rely heavily on forecasting our "billing pipeline".   Billing Pipeline is defined in our organization  by: All billings for a specified date range + (all open sales orders + deliveries)  not yet billed but due by  a specified due date = Billing Pi

  • Unplanned delivery costs

    Our main vendor is a ERS vendor and freight vendor is  without ERS. We have some freight related condition types in PO and maintained freight vendor in the same. We are running ERS for main vendor and arranging payment to freight vendor with MIRO. As

  • Java program in Jsp

    Dear Friends, I am new to jsp Can embed java program in my jsp page ? my java program contains outputstream, printwriter etc., can i put those in jsp program ? please help me. Thanks in advance yours rajesh

  • Log in faild, but Log in classic webtop ok...!?

    Dear all ! I have installed tarntella version 4.10.903 on our tarantella server. We use Secure SSL connection, Port 443, https, over Proxy Server. When I try to login on classic weptop all ok. But when I try to log in to Secure Global Desktop Enterpr

  • How to download an IDOC in XML or spreadsheet with well structured.

    Dear Experts, I am currently display an IDOC in WE02. May i know how to download this IDOC into XML format or spreadsheets format and well structured with Hierarchy level.. Thank you very much