Bufferreader & system.in.read

hello, everyone
I am confused by the java input from the keyboard. Why sometime we use bufferreader, but sometime using system.in.read? What is their difference? When should I use bufferreader and system.in.read?
Thank you!~

System.in is used when you want to read from the keyboard.
BufferedReader is a class that you can wrap around any other reader, and it provides buffering so that performance is better. A BufferedReader isn't tied to a particular physical device.

Similar Messages

  • Problem with "System.in.read()" read() method!

    import java.io.*;
    import java.lang.*;
    class Count {
    public static void main(String args[]) throws IOException
    int count = 0;
    while (System.in.read()!=-1)
    count++;
    System.out.println("Input has " + count + " chars.");
    in this code the loop stucks and it increments the count variable infinitely of course as long as i hit enter. I am trying to understand the problem with read() method of system class's in object. in its definition it says; when the inputstream ends it returns -1, but in this code it does not return -1 ever. another question of mine is that what args[] array do? what does it store??

    Java doesn't bother much with the dos console and it a bit limited and limiting - no pretty colours /graphics options - just text - that's because java graduates to GUI's where there is laods of power and object /component support to do everything and everything you could imagine and more. System.in.read() ??? - thats a fine start!
    what args[] array do? what does it store??
    Good question !
    It provides a means of passing a parameter argument from the command line to the program - consider this;-public class HelloWithArgs {
       public static void main(String[] args) {
          System.out.println("Hello I am " + args[0]);
    }What does it do and how does it work? Or this;-public class HelloWithArgs2 {
       public static void main(String[] args) {
          try{
             String myName = args[0];
          catch(ArrayIndexOutOfBoundsException aob){
              System.out.print("No names: program will end");
              System.exit(0);
          System.out.println("Hello I am " + myName);
    }Study them and have fun. Though to answer the question -
    " public static void main(String[] args) {" // or
    " public static void main(String[] parameters) {"
    is the 'entry point' of all java programs, in order to do something it has to have a main() method and if youre going to pass on parameters, then why not a String array? If you think about it anything else would be fairly useless.

  • I cannot update from OS 10.9.4 to 10.9.5. I get a message saying: File couldn't be installed error (513). I have configured my OS so that I have read and write permission followed by system with read and writ permission. Can someone help me? Thanks.

    I cannot update from OS X 10.9.4 t0 10.9.5> Whenever I try I get the following message: File couldn't be installed error (513) and something about not having the proper permission.  Under the Macintosh HD sharing and permissions settings I have customized the settings so that (Me) has read and write permission followed by the system with read and write permission, wheel and everyone have Read permissions.
    I have no problems updating apps such as Adobe CC or iTunes but cannot update the operating system, can someone help me? Thanks.

    1. Restart the computer in safe mode. Certain caches maintained by the system will be rebuilt.
    Safe mode is much slower to start up than normal. The next normal startup may also be somewhat slow.
    When the login screen appears, restart as usual (not in safe mode) and test. There's no need to log in while in safe mode.
    Note: If FileVault is enabled, or if a firmware password is set, or if the startup volume is a software RAID, you can’t start in safe mode. In that case, go to Step 2.
    If there's no change after taking this step, continue.
    2. Back up all data before proceeding.
    Triple-click anywhere in the line below on this page to select it:
    /var/folders
    Right-click or control-click the highlighted line and select
              Services ▹ Reveal in Finder (or just Reveal)
    from the contextual menu.* A folder should open with an item named "folders" selected. Move the selected item to the Trash. You may be prompted for your administrator login password. Restart the computer and empty the Trash.
    *If you don't see the contextual menu item, copy the selected text to the Clipboard by pressing the key combination  command-C. In the Finder, select
              Go ▹ Go to Folder...
    from the menu bar and paste into the box that opens by pressing command-V. You won't see what you pasted because a line break is included. Press return.

  • System goes read only, after reboot all is fine for a day or two

    OK, so here's the problem, I got a new PC, all fanless, SSD hard and all.
    Works well for a day or so, then goes read only. For example - I come back from work, type something in the terminal and I get Input/Output Error. I cannot reboot, it says Input/Output Error as well.
    So I hard-reset it, it boots up, everything is fine again for a day or two.
    The HDD is Corsair CSSD-F40GB2, the MB is Gigabyte H55N-USB3, proc i3 540,
    The / and /home are both ext4 mounted with defaults,noatime,discard.
    I tried with/without discard.
    I also tried changing the SATA/power cables - same results.
    I also tried enabling/disabling features in BIOS like DMA/SMART/AHCI/compatibility stuff - same results.
    Here's a dmesg I managed to get (errors are near the end).
    http://pastebin.com/vJfdW90z
    And here's a smartctl -a /dev/sda:
    http://pastebin.com/eQxASEBM
    Any suggestions are welcome. Also is there some diagnostic app for Corsair SSD that I can run and check the drive?
    Cheers.

    Well I don't recall how freshly booted, it was the only time that the system was read-only - giving input/output error to everything but dmesg was working so I saved it all to pastebin.
    The system is a PC so I never tried anything else different from poweroff/reboot (works fine).

  • Make System.in read input from a command prompt

    How can i make System.in read input from a command prompt which is opened after program
    is started. Please note that program starts without commad promt. Can u plz help?
    sharmila

    System.in DOES read from the command shell that you start the app in.
    What you don't have is a prompt.
    You should know about Java Almanac. There are code samples for simple things like I/O that everyone should know about. There's an example there to help you.
    MOD

  • I was using system.in.read function...

    i was using system.in.read function to read input.when i used the his function
    again for the second time it read the same input which was read first
    which is pretty obvious that the initial contents of the input buffer still
    contains the previos contents which is not being overwritten by the new input
    contents.can someone please tell me how to read the contents using the
    same function.i know there are a lot of other ways to accepting inputs
    but i wanted to clear this doubt of system.in.read before moving on to
    ip/op chapter of java..........

    if your reading textual data use a buffered reader.
    BufferedReader br = new BufferedReader(
                            new InputStreamReader(System.in));It will make your life easier.
    The System.in doesnt appear to support a flush method by itself. Also it typically reads in byte data, so you would have to build your strings to manipulate them.
    Unless of course, this is what you want.

  • "switching of echoing characters" in System.in.read(), System.in.readLine()

    Hi,
    I am trying to create an effect in
    System.in.read() or
    System.in.readLine()
    by not echoing the characters, if anyone knows please let me know,
    thanx!!!!

    I raised this issue also in another thread.
    Actually I am pretty p.o. This issue pops up over and over again but the people at Sun systematically deny the problem and simply do nothing about it. I know, it's not as interseting as EE, 3D graphics or Swing, but it is asked for by many peaople over and over again.
    I simply don't understand what is so difficult in the method:
    System.in.setEcho(boolean) or System.in.setEcho(char)

  • Do you use System.in.read()??

    As above, don't u guys find that java reading in of inputs from the command line are pretty cumbersome?

    This is good I use it.
    * Read a line of input from System.in and convert the entire line to
    * a String or a number (int or a double). Kills the program on user
    * error.
    * @author Suzanne Menzel
    * Usage: Keyboard.readLine() ==> next line of user input as a String
    * Keyboard.readInt() ==> next line of user input as an int
    * Keyboard.readDouble() ==> next line of user input as a double
    import java.io.BufferedReader;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.IOException;
    public class Keyboard { 
    public static String readLine() {
    String line = "";
    try {
    line = reader.readLine();
    catch (IOException e) {
    System.out.println("Error in Keyboard class:" + e);
    quit();
    return line;
    public static int readInt() {
    int n = 0;
    try {
    n = Integer.parseInt(readLine().trim());
    catch (NumberFormatException e) {
    System.out.println("Error in Keyboard.readInt()\n" + e);
    quit();
    return n;
    public static double readDouble() {
    double n = 0.0;
    try {
    n = Double.parseDouble(readLine().trim());
    catch (NumberFormatException e) {
    System.out.println("Error in Keyboard.readDouble()\n" + e);
    quit();
    return n;
    private static void quit() {
    System.out.println("\nTerminating the program.");
    System.exit(1);
    private static BufferedReader reader =
    new BufferedReader(new InputStreamReader(System.in));

  • New bie problem System in read

    freinds i recently downloaded an ebook n I HAVE 1 QUERY IF any of U COULD DEBUG THAT TOO I would REALLY BE A HAPPY MAN
    friends WITH BELOW MENTIONED CODE, PROBLEM IS THAT WHEN USER ENTERS SUPPOSE 1,48 AUTOMATICALLY GETS ADDED TO IT N WHEN I SUBTRACT 48 FROM USERS RESPONSE,AGAINT THEN WHEN 48 IS ENTERED IT AUTOMATICALLY MAKES IT 4 WHICH IS KINDA GETTING ON MY NERVES
    KINDLY HELP
    class forex{
    public static void main(String args[])
    throws java.io.IOException{
    int a,b;
    int c;
    //Clrscr();
    System.out.println("enter any no &press enter \n");
    c = System.in.read();
    System.out.println("u entered\n"+c);
    for(a=1;a<=c;a++)
    for(b=1;b<=a;b++)System.out.print("*");
    System.out.print("\n");
    }

    c = System.in.read();This does not return the number the user entered. It returns the character code of the character that was entered (i.e., the ASCII code).
    Please learn how to use your keyboard properly, do not type ALL CAPS and watch your spelling.

  • Really strange: System.in.read()

    Hello,
    this code:
    System.out.print( "command?" );
    while(true) {
        try {
            int input = System.in.read();
            if( input == 50 )
                System.out.println( "Input: " + input );
        catch(IOException) {
            System.out.println( "Who cares about exceptions?" );
        System.out.print( "command?" );
    }produces this:
    command?2
    Input: 50
    command?command?command?Why does it print command? three times? Any way around this?
    Thank you!
    -mike

    > System.out.print( "command?" );
    >
    while(true) {
    try {
    int input = System.in.read();
    if( input == 50 )
    System.out.println( "Input: " + input );
    catch(IOException) {
    System.out.println( "Who cares about exceptions?" );
    System.out.print( "command?" );
    } I have not tested your code, but I am surprised that it compiles. You are missing an '}' before your catch statement, and you need an identifier for your IOException.

  • I have a two screen system that reads left to right.  With Yosemite it now reads right to left.  How do I fix it?

    I have a two screen system that read left to right.  With Yosemite the screens have switch and now the mouse and my brain have to read right to left.  Any ideas how to fix this?

    a brody,
    After further scrutiny your solution solved the mouse problem of going left to right.  But now the home screen problem.  Display two on the right still has the dock below and the menu bars.  Any ideas how to fix this?

  • Set sharing on system to read only now computer wlll not boot up

    set sharing on system to read only now computer wlll not boot up

    Hello skiboat2, 
    Because the permissions have been changed, you will need to put them back to what they were before. One of the ways to do that is to reinstall your OS X to make sure that everything permission wise gets put back to what it needs to be to work properly. Based of to the operating system that you say you have, I have provided the steps for reinstalling Snow Leopard. When doing this, it does not overwrite your personal data; it only touches the operating system. 
    Mac OS X 10.6: Reinstalling Mac OS X
    http://support.apple.com/kb/PH6606
    Regards,
    -Norm G.  

  • How does the System.in.read() works?

    Hi!I'm trying to read some chars from the console.So here is my code of reading the two chars:
           char ch1='\u0000';
           char ch2='\u0000';
           System.out.print("Enter the first char:");
           ch1=(char)System.in.read();
           System.in.read();
           System.out.print("Enter the second char:");
           ch2=(char)System.in.read();
           System.out.println("You have typed the following letters:"+ch1+" , "+ch2);My problem is that if I don't add the System.in.read(); line after reading the first char i wont be able to read the second.But I saw on a code on the net that they put it.So I've put it too but don't understand what it does.I mean the System.in.read(); function reads until it gets -1.But in my case it's gonna get '\n'.So how does this function works?Thank you!
    Edited by: jcoder86 on Oct 9, 2009 5:36 AM

    jcoder86 wrote:
    Hi!I'm trying to read some chars from the console.So here is my code of reading the two chars:
    char ch1='\u0000';
    char ch2='\u0000';
    System.out.print("Enter the first char:");
    ch1=(char)System.in.read();
    System.in.read();
    System.out.print("Enter the second char:");
    ch2=(char)System.in.read();
    System.out.println("You have typed the following letters:"+ch1+" , "+ch2);My problem is that if I don't add the System.in.read(); line after reading the first char i wont be able to read the second.But I saw on a code on the net that they put it.So I've put it too but don't understand what it does.I mean the System.in.read(); function reads until it gets -1.But in my case it's gonna get '\n'.So how does this function works?Thank you!
    Edited by: jcoder86 on Oct 9, 2009 5:36 AMThat's wrong. System.in.read() reads a byte from the stream. -1 is returned if the end of stream has been reached (that usually doesn't happen if you read from stdin)
    The second System.in.read() is there to throw away the line terminator.

  • When plugging in an iPad in Apple Configurator, it is not being read under USB Connected so I can't update it.  Any ideas on how to get the system to read the iPad?

    When plugging in an iPad in Apple Configurator, it is not being read under USB Connected so I can't update it.  The iPhoto window opens up and reads the photos on the iPad, so it is connecting to the computer.  Earlier today I wasn't having any problems.  I have shut down the iPad and the computer and started over, but that didn't help.  Any ideas on how to get the system to read the iPad so I can update the apps on it?

    Hi, is the problem just to update your apps on your iPad? Here is what you should check. Is the iTunes on your computer updated to the latest version? Does your iPad needs to be updated? Do you have enough storage on your iPad to do the update? On your device is your iCloud back up checked?
    Go to Settings - iCloud - Backup/Storage - see if its checked, and try unchecking it before connecting it to the computer.
    Please let me know if you need any further assistance.

  • Can the Adobe PDF plugin carry exact phrase search criteria through from source system into Reader?

    In SharePoint 2013 if you search for an exact phrase and then view a PDF that is returned by the search (in Reader via the PDF plugin) then the Reader will treat the complete phrase as individual words.
    For example, search for "High Court" in SharePoint, get returned a set of PDF documents, and when you view one of them through the Reader the hit highlighting will be for each instance of "High" or "Court".
    What is wanted is hit highlighting only of instances of "High Court".
    I get the same behavior if the Adobe PDF plugin is installed with the Filesite DMS. So it seems to be standard behavior for the Adobe PDF plugin
    Is there a way to make the Adobe PDF plugin carry exact phrase search criteria through from source system into Reader? And then hit highlight the exact phrase only.

    Hi Sam,
    You can opt for 'Advance Search' option in Reader to match the whole words to get to the specific documents.
    Regards,
    Rave

Maybe you are looking for