Why using BefferedReder and PrintWriter if we have Input/OutputStream

hi
i've been wondering if we have an InputStream and OutputStream why using PrintWriter and BufferedReader
                in=s.getInputStream();
                out=s.getOutputStream();
                bfr=new BufferedReader(new InputStreamReader(in));
                writer=new PrintWriter(out,true);where s ia a socket
Edited by: scrolldown on Mar 29, 2008 3:03 AM
Edited by: scrolldown on Mar 29, 2008 3:04 AM

Everything that is a InputStream/OutputStream is used to handle raw byte streams.
Everything that is a Reader/Writer is used to handle character data.
In your case the InputStreamReader provides the conversion from raw bytes to character data. Usually it does so using some specified encoding, in your case it uses your platform default encoding.
The PrintWriter does the same for the output, but doesn't allow you to specify an encoding (for this you'd have to use an OutputStreamWriter).
And please note, that it's usually an error to do any byte -> character or character -> byte conversion without specifying a character set, especially when handling sockets, because then the platform default encoding will be used which can be different from computer to computer and thus you don't know what exactly is sent over the wire.
If you don't know what I'm talking about, then read [The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)|http://www.joelonsoftware.com/articles/Unicode.html], an excellent article that gives a good overview over the matter.

Similar Messages

  • I don't understand the thing you call live bookmarks never used it, and most forums I have used notify VIA E-mail not giving out my E-mail address information when a reply has been made to the thread in question.

    So how do I get notified of updates in this forum? As I said: I don't understand the thing you call LIVE BOOKMARKS I have never used them, and most forums I have used notify VIA E-mail not giving out my E-mail address, or other private information when a reply has been made to the thread in question, so how do I get notified of updates in this forum? I have seen no normal options for setting my viewing preferences used for this forum. Thank You.

    Thanks for your reply via email/msg. He wrote:
    If you are interested in the actual design data for the Xeon processor, go to the Intel site and the actual CPU part numbers are:
    Xeon 4 core - E5.1620v2
    Xeon 6 core - E5.1650v2
    Xeon 8 core - E5.1680v2
    Xeon 12 core - E5.2697v2
    I read that the CPU is easy to swap out but am sure something goes wrong at a certain point - even if solderedon they make material to absorb the solder, making your work area VERY clean.
    My Question now is this, get an 8 core, then replace with 2 3.7 QUAD CHIPS, what would happen?
    I also noticed that the 8 core Mac Pro is 3.0 when in fact they do have a 3.4 8 core chip, so 2 =16? Or if correct, wouldn't you be able to replace a QUAD CHIP WITH THAT?  I;M SURE THEY ARE UO TO SOMETHING AS 1) WE HAVE SEEN NO AUDIO FPU OR PERHAPS I SHOULD CHECK OUT PC MAKERS WINDOWS machines for Sisoft Sandra "B-E-N-C-H-M-A-R-K-S" -
    SOMETHINGS UP AND AM SURE WE'LL ALL BE PLEASED, AS the mac pro      was announced Last year, barely made the December mark, then pushed to January, then February and now April.
    Would rather wait and have it done correct than released to early only to have it benchmarked in audio and found to be slower in a few areas- - - the logical part of my brain is wondering what else I would have to swap out as I am sure it would run, and fine for a while, then, poof....
    PEACE===AM SURE APPLE WILL BLOW US AWAY - they have to figure out how to increase the power for 150 watts or make the GPU work which in regard to FPU, I thought was NVIDIA?

  • Does anyone know how well the Intel Iris Pro installed on new 15" MacBook Pros performs using Photoshop and Lightroom. I have seen some differing opinions out there, and I would rather not shell out the extra cash for the Nvidia if I don't have to. I most

    Does anyone know how well the Intel Iris Pro installed on new 15" MacBook Pros performs using Photoshop and Lightroom?  I have seen some differing opinions out there, and I would rather not shell out the extra cash for the Nvidia if I don't have to. I mostly do photo editing for business and personal use. I have not used the 3D function in Photoshop, but I would like to know that I could.

    You could download a trial and see how well it works before committing to a subscription. You get 30 days to decide.
    Photo editor | Download free Adobe Photoshop CC trial
    Photo editor app | Download free Adobe Photoshop Lightroom 5 trial
    Gene

  • "Unable to Connect" using Firefox and Windows 7. Have tried all the suggestions on this website to no avail. I need firefox for my work! Please help!

    "Unable to Connect" using Firefox and Windows 7. Have tried all the suggestions on this website to no avail. I need firefox for my work! Please help!
    == This happened ==
    Every time Firefox opened
    == Since I downloaded Firefox

    same here my AV is ESET, i already unblock it but no use can't connect to the internet..

  • I am using xp and I don't have the wpa2 personnel option to set it up.

    I have a wrt54g3g. I have it set up using security wpa2 personnel with aes. I have the password set and eveything. I can't get my lap top set up to connect. I am using xp and I don't have the wpa2 personnel option to set it up. I need some help on this? Thanks
    Message Edited by ewoolwine on 04-06-200702:46 PM

    Make sure you have Windows XP service pack 2 (SP2) installed.
    Also, WPA2 is the same as WPA with AES.
    Hope this helps.
    Message Edited by toomanydonuts on 04-07-200702:50 AM

  • I have lost my iPad 3 (3G). I do not use iCloud and I do not have the 'Find my iPad' app installed. What can I do to find it? Is there another way to bring up a map of where it is?

    Although I have Telstra 3G
    I do not use iCloud and I do not have the 'Find my iPad' app installed. What can I do to find it? Is there another way to bring up a map of where it is?
    I dont know the opperating system but I only got it recently...
    I also have a mac book pro also without iCloud.

    Without Find My iPad having been enabled on it then there isn't any way to locate it - and that would only work if it's connected to a network and hasn't been wiped or had Find My iPad disabled on it.
    If you think that it was stolen then you should report it to the police. You should also contact your carrier and change your iTunes account password, your email account passwords, and any passwords that you'd stored on websites/emails/notes etc.

  • HT4437 Is it possible to zoom in photos when using airplay? It seems not to work at all. I can only zoom in if i use mirroring and even then i have to reconnect mirroring each time I chage an albumor even go from the photo to the album level.

    Is it possible to zoom in photos when using airplay? It seems not to work at all. I can only zoom in if i use mirroring and even then i have to reconnect mirroring each time I chage an albumor even go from the photo to the album level.

    No.
    I find it extremely frustrating that Apple does not care for such an obvious bug affecting one of the basic funcionalities of AirPlay. Unless, of course, if there's something I don't know - but I've done some research and it seems that plenty of people have same issue and no solution is settled.

  • I rec'd an alert that my "Apple ID and phone no. are now being used for iCloud on a new iPhone."  I am not using iCloud and I don't have a new iPhone.  Is this something to worry about?

    I rec'd an alert that my "Apple ID and phone no. are now being used for iCloud on a new iPhone."  I am not using iCloud and I don't have a new iPhone.  Is this something to worry about?

    Howdy Libbidydooda,
    There are a couple of possibilities that may apply to the email you have received regarding your Apple ID. The first is that the email may be a legitimate warning that your Apple ID has been compromised. For this reason I would suggest that you change the password to your Apple ID as soon as possible. Use the instructions on this page -
    Apple ID: Changing your password - Apple Support
    In order to increase security for your Apple ID you may want to set up and use two-step verification. See this article for information about it -
    Frequently asked questions about two-step verification for Apple ID - Apple Support
    The second possibilty is that the email is an attempt at "phishing" in order to get you to reveal personal information. Typically this is done with an email that looks like it comes from an official source but has links to web pages that, while they may look like they are real, may actually be gathering your information for use by others. This article has more information about phishing -
    Identifying fraudulent "phishing" email - Apple Support
    For this reason it is important that you do not follow any links in the email, as they may compromise your security.
    Thanks for using Apple Support Communities.
    Best,
    Brett L 

  • How can I cancel my auto-renewal payments I don't use it and every month I have to pay

    How can I cancel my auto-renewal payments I don't use it and every month I have to pay.

    http://helpx.adobe.com/x-productkb/policy-pricing/return-cancel-or-change-order.html

  • Why use cursor and for loop?

    Hi All
    So in general why would we use a cursor and a for loop to do update in a stored procedure?
    Why wouldnt we just use a single update statement ?
    is there compelling reason for using a cursor and a for loop: I am reading some code from a co-worker that the business logic for the select (set need to be updated) is complex but the update logic is simple (just set a flag to (0 or 1 or 2 or 3 or 4).
    But eventually the select come down to a key (row_id) so I re-write it using just a single sql statement.
    The size of the main table is about 2.6 to 3million rows
    Any thoughts on that??
    The code below I just do a google for cursor for update example in case for something to play with
    -Thanks for all your input
    create table f (a number, b varchar2(10));
    insert into f values (5,'five');
    insert into f values (6,'six');
    insert into f values (7,'seven');
    insert into f values (8,'eight');
    insert into f values (9,'nine');
    commit;
    create or replace procedure wco as
      cursor c_f is
        select a,b from f where length(b) = 5 for update;
        v_a f.a%type;
        v_b f.b%type;
    begin
      open c_f;
      loop
        fetch c_f into v_a, v_b;
        exit when c_f%notfound;
        update f set a=v_a*v_a where current of c_f;
      end loop;
      close c_f;
    end;
    exec wco;
    select * from f;
    drop table f;
    drop procedure wco;
    Joining multiple tables
    create table numbers_en (
      id_num  number        primary key,
      txt_num varchar2(10)
    insert into numbers_en values (1, 'one'  );
    insert into numbers_en values (2, 'two'  );
    insert into numbers_en values (3, 'three');
    insert into numbers_en values (4, 'four' );
    insert into numbers_en values (5, 'five' );
    insert into numbers_en values (6, 'six'  );
    create table lang (
       id_lang   char(2) primary key,
       txt_lang  varchar2(10)
    insert into lang values ('de', 'german');
    insert into lang values ('fr', 'french');
    insert into lang values ('it', 'italian');
    create table translations (
      id_num    references numbers_en,
      id_lang   references lang,
      txt_trans varchar2(10) not null
    insert into translations values (1, 'de', 'eins'   );
    insert into translations values (1, 'fr', 'un'     );
    insert into translations values (2, 'it', 'duo'    );
    insert into translations values (3, 'de', 'drei'   );
    insert into translations values (3, 'it', 'tre'    );
    insert into translations values (4, 'it', 'quattro');
    insert into translations values (6, 'de', 'sechs'  );
    insert into translations values (6, 'fr', 'six'    );
    declare
      cursor cur is
          select id_num,
                 txt_num,
                 id_lang,
                 txt_lang,
                 txt_trans
            from numbers_en join translations using(id_num)
                       left join lang         using(id_lang)
        for update of translations.txt_trans;
      rec cur%rowtype;
    begin
      for rec in cur loop
        dbms_output.put (
          to_char (rec.id_num         , '999') || ' - ' ||
          rpad    (rec.txt_num        ,   10 ) || ' - ' ||
          rpad(nvl(rec.txt_trans, ' '),   10 ) || ' - ' ||
                   rec.id_lang                 || ' - ' ||
          rpad    (rec.txt_lang       ,   10 )
        if mod(rec.id_num,2) = 0 then
          update translations set txt_trans = upper(txt_trans)
           where current of cur;
           dbms_output.put_line(' updated');
        else
          dbms_output.new_line;
        end if;
      end loop;
    end;
    /Edited by: xwo0owx on Apr 25, 2011 11:23 AM

    Adding my sixpence...
    PL/SQL is not that different from a SQL perspective than any other SQL client language like Java or C# or C/C++. PL/SQL simply integrates the 2 languages a heck of a lot better and far more transparent than the others. But make no mistake in that PL/SQL is also a "client" language from a SQL perspective. The (internal) calls PL/SQL make to the SQL engine, are the same (driver) calls made to the SQL engine when using Java and C and the others.
    So why a cursor and loops in PL/SQL? For the same reason you have cursors and loops in all these other SQL client languages. There are the occasion that you need to pull data from the SQL engine into the local language to perform some very funky and complex processing that is not possible using the SQL language.
    The danger is using client cursor loop processing as the norm - always pulling rows into the client language and crunching it there. This is not very performant. And pretty much impossible to scale. Developers in this case views the SQL language as a mere I/O interface for reading and writing rows. As they would use the standard file I/O read() and write() interface calls.
    Nothing could be further from the truth. SQL is a very advance and sophisticated data processing language. And it will always be faster than having to pull rows to a client language and process them there. However, SQL is not Turing complete. It is not the procedural type language that most other languages we use, are. For that reason there are things that we cannot do in SQL. And that should be the only reason for using the client language, like PL/SQL or the others, to perform row crunching using a client cursor loop.

  • Why does FF18 (and not older releases) have new, severe font display issues in some contexts?

    When I upgraded to FF18 in Windows XP, all the sample pages (more than 200) in my portfolio site were effectively rendered unreadable in FF18 in XP. I also noticed the darker themes in Gmail had some of the same issues, though much less severe. I see none of these problems in FF18 on OS X using the latest version of the OS (Version 10.8: "Mountain Lion"). The issues seem to have no relationship to the fonts specified, although on one system, the bolder Arial in Gmail's top menubar looked much worse than unbolded Arial inside the inbox.
    I narrowed down the portfolio page issues to two main contributing factors:
    1. Translucent CSS opacity setting in a non-containing layer below the layer containing the text. To try being a bit more clear, the layer that actually contained the text and its background was NOT using any opacity settings. Think of the lightbox effect, if you've heard of that, to pop-up a page inside the existing browser window rather than in a new window, which typically uses a translucent overlay outside of the text area that reveals some of the background of the opening page.
    2. The text layer used white and other light-colored text on a dark background (#262626).
    Although I've I spent several days redesigning and reworking my pages to protect them from future potential rendering issues, I'd still like to know more about what's causing this. I've worked around somewhat similar issues in other browsers (mainly ie and chrome), but never so severe as these latest ones in FF18.
    I tried unchecking the hardware acceleration checkbox in Options, and tried reversing the gfx 'azure' and '2d' options in about:config. I also tried disabling all add-ons. However, none of this made any difference in either Gmail or my own pages.
    I can't realistically ask my potential clients to fiddle with all of these settings, so that is a major reason for asking. I could post a couple of screenshots of my Gmail inbox, although I don't see any place in this form for file uploads.

    Here're two screenshots showing the more severely unreadable rendering when a non-containing translucent layer is below the text layer (Item #1 in opening post).
    1: The first screenshot shows 13px Calibri (Windows system font) body text at #ffffff (white) foreground color body text over a #262626 (dark gray) background. The background color of the 0.5 opacity translucent layer (visible at top and left sides of screenshot) is #DFDBCD. The subheads are 18px #fff Calibri.
    2: The second screenshot shows 13px body text at #ffffff (white) foreground color body text using an open source font over a #262626 (dark gray) background. The background color of the 0.5 opacity translucent layer (visible at top and left sides of screenshot) is #DFDBCD. The subheads are 18px #fff using an open source font.

  • Writing to file using PrintStream and PrintWriter...

    I tried to write a string to a file, it actually ADD the string to the bottom of the text file without deleting what was already in there. at first I use PrintStream, it worked fine when run it from my MS-J++6.0, but it says "PrintStream has been deprecated by the author of java.io.printstream", and when I try to run it from IE it doesn't even work. then I look into the MSDN, it says jdk 1.1 prefer to use PrintWritier, so I change it to PrintWriter, no more error message but now the file only records the last string I entered and deleted all the text I had in there before. and it still doesn't work when I try to run it from IE. And for some reason, the program will creat the text file on my desktop(winXP) instead in the same folder where the java files are....
    Please help me understand what's wrong and how to solve it.. thank you. here is my code...
    public void storing(String msg)
              PrintWriter ps = null;
              try
                   ps = new PrintWriter(new FileOutputStream("collect.txt"), true);
                   ps.println(msg);
              catch (IOException e)
                   feedback.append("Cannot write to file.");
              finally
                   if(ps != null)
                        ps.close();

    cuz what I am doing is to have the user input 30 lines of messages, each time a message is written, they press a "next" button then that line of message will be saved to file, then the user can write the next line. I do this becuz I am affraid that the user will close the applet before he finishes all 30 line, if he does that, I still want to get as much line that the user has wrote that's why I have it write to file each time a line is written. So if I open a file at the beginning of the program, will it encounter any problem if the user close the applet without close the file??
    thanx.

  • HT1414 my ipad is 5 weeks old and yesterday i was using it and it quite. i have tryed two different chargers and it is completely dead. no sound or image. can i get this running again?

    new ipad 5 weeks old. ipad 2    no display no sounds.  tryed two chargers overnight    blank screen

    If the unit has NEVER been jailbroke, first try a system reset.  It cures many ills and it's quick, easy and harmless...  Hold down the on/off switch and the Home button simultaneously until you see the Apple logo.  Ignore the "Slide to power off" text if it appears.  You will not lose any apps, data, music, movies, settings, etc.
    If the Reset doesn't work, try a Restore.  Note that it's nowhere near as quick as a Reset.  It could take well over an hour!  Connect via cable to the computer that you use for sync.  From iTunes, select the iPad/iPod and then select the Summary tab.  Follow the on-screen directions for Restore and be sure to say "yes" to the backup.  You will be warned that all data (apps, music, movies, etc.) will be erased but, as the Restore finishes, you will be asked if you wish the contents of the backup to be copied to the iPad/iPod.  Again, say "yes."
    At the end of the basic Restore, you will be asked if you wish to sync the iPad/iPod.  As before, say "yes."  Note that that sync selection will disappear and the Restore will end if you do not respond within a reasonable time.  If that happens, only the apps that are part of the IOS will appear on your device.  Corrective action is simple -  choose manual "Sync" from the bottom right of iTunes.
    If you're unable to do the Restore, go into Recovery Mode per the instructions here.  You WILL lose all of your data (game scores, etc,) but, for the most part, you can redownload apps and music without being charged again.  Also, if you have IOS-7, read this.

  • Why use setters and getters?

    Hi.
    I've been wondering woudn't a function with return do the same thing as a get function with return?
    Ex:
    var age:Number = 16;
    function get Age() {
         return age;
    isn't the same as:
    function Age() {
         return age;
    Thanks.

    I respectfully disagree with the statements that it is a matter of nomenclature. Although there are a lot of cases when accessors (getters/setters) are overused, they are definitely extremely useful features of any OO language. In some case code would be much longer and more cumbersome without accessors. I must say that with code written on timeline accessors are less useful (although I can see plenty of cases one can utilize them). When code is written in classes - accessors are indispensable.
    With your age example it is really a matter of preference. But if you need to do more with age - you would definitely appreciate getters/setters.
    For example:
    Say you have a class Person and it has property age:
    public var age:int = 0;
    Somewhere we instantiate this class:
    var myPerson:Person = new Person();
    Now we set age:
    myPerson.age = 23;
    trace(myPerson.age); // returns 23
    Just imagine you instantiate this variable in 100 of places.
    When you think you are done, your boss comes to you and says: “I want you when they set the age also to evaluate what age group person belongs to.”
    If there were no getters/setters – you would have a very hard time chasing all 100 instances in your program and changing your Person class architecture. With accessors you will spend a few minutes only. You can do the following:
    // change the variable to private
    private var _age:int = 0;
    // create accessors
    public function set age(a:int):void{
         _age = a;
         // here you evaluate age
         if (_age < 10) {
              trace("child");
         else if (_age > 10 && _age < 20) {
              trace("teenager");
         else if (_age > 20 && _age < 30) {
              trace("young");
         else {
              trace("too old to bare :-(");
    public function get age():int{
         return _age;
    As you can see you changed the code in one place and while not doing a thing in any of 100 places you instantiated the Person class.
    Again, your boss can come back and ask to restrict the age to people older than 20.
    So may write:
    public function set age(a:int):void {
         if (a > 20) {
              _age = a;
    Again, you met requirements and did not change any code anywhere else.
    One more request from the boss. Say, he wants you to count how many times age was changed. You can use setter to do that:
    private var getterCounter:int = 0;
    public function get age():int {
         getterCounter++;
         return _age;
    You wouldn’t be able to do all these things if there were not accessors.
    Still the use of age variable will stay the same:
    var myPerson:Person = new Person();
    myPerson.age = 34;
    trace(myPerson.age);
    Welcome to scalability and encapsulation. It doesn’t matter what you do when age is set inside Person class – it will not break code anywhere else.
    There are millions more useful cases when getters/setters come handy.

  • Why the iphone and Ipad if you have a password and you try turning off the password does not ask you to turn it off?

    my girlfriend stole his iphone 5 and could not find my iphone locate because they turn it off.
    my question is, if the iphone 5 have a password to access does not ask why when I try to shut down?
    apple should of IOS patching to ask for the password to turn off the device.

    I see your point but if they are running iOS 7 on the iPhone they can locate it next time it is connected to the internet. Whoever has the iPhone cannot stop this without turning Find My iPhone off which requires the Apple ID password.
    At some point in time that person will connect the iPhone to the internet and when they do the owner will have a location, if they restore the iPhone in recovery mode they won't be able to activate it so the iPhone will be useless to them.

Maybe you are looking for

  • Using An External Hard Drive With An iBook

    I just got an external hard drive to hold my large iTunes library because it was filling up my disk completely. I don't want it to be backing up the library, I want it to be the library so that it isn't taking up space on the computer's hard drive. I

  • Elements 2 won't save a file as JPEG

    Hi: os is win xp sp2 home ed. using elements 2 for a very long time but suddenly, it will not save an image as JPEG. the file saves as a JPEG (but no thumbnail image) and can not be opened by any program - including elements 2! Elements 2 will save a

  • KT 133A Based Motherboards

    Will any of the kt133a based motherboards (more specifically my ms-6330 k7t turbo 2 v5.0) be able to support the new athlon x'ps (2600+ & 2400+)? or is the kt133a chipset and sdram too slow and old for  them?

  • Can a iTouch connect to a local iTunes Server

    Hi All Will you be able to connect to a local iTunes Server from your iTouch, or is this a no go? More precise - Can a iTouch connect to a LAN Disk that has support for iTunes Service? Regards Torben

  • LabVIEW 8.0.1 Update for Linux

    Hello, I just downloaded the update for LabVIEW for Linux an tried to install like it is described. The following output occurs: Installing... /bin/sh: /soft/natinst/lv801-update/bin/INSTALL.norpm: No such file or directory /bin/sh: /soft/natinst/lv8