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.

Similar Messages

  • When I activated VoiceOver, capital s was used to start reading.  I cannot turn it off so as to be able to use capital s in ordinary utilities (Word, textedit..)  Restarting did not help.

    When I activated VoiceOver, capital s was used to start reading.  I cannot turn it off so as to be able to use capital s in ordinary utilities (Word, textedit..)  Restarting did not help.

    Hi, benson -
    If it is a matter of VoiceOver being turned on when you press Shift-S, you can change the keyboard command key combo for that. Open System Preferences, select the Keyboard item. In the new window, click the Keyboard Shortcuts button.
    In the left list, click Universal Acess. In the new list on the right, be sure the last item, "Turn VoiceOver on or off", is checkmarked, then click the command-key setting on the right of that line. A small text box will open - enter the new command-key combo you wish to reset it to.
    Suggestion - the original setting for that is Command-F5 (that's the number 5, not the letter S). Unless you have a particular need to use Command-F5 for something else, I would reset it to that. If you do need to set it to something else, include the Command-key as part of the combo - doing so prevents accidental activation when using routine keyboard strokes.

  • 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));

  • Getting a number from  (char)System.in.read

    I am very new to java so please forgive the seemingly basic question.
    When I try to simply get a number for input into a program, and I use (char)Sysytem.in.read(),
    it only gives me the acutual Keyboard number (ie.. 2 = 50, 1 = 49).
    Even when I try to parse an Integer using :
    public static void getNum( ) throws NumberFormatException
         char char1;
         String String1 = new String ("");
         int X;
         char1 = (char)System.in.read();
    while ( char1 <= '0' && char1 <= '9' )      
         String1 = String1 + char1;
         char1 = (char)System.in.read();
         X = Integer.parseInt(String1);
    System.in.read();
         return X;
         System.out.println(X);
    This gives me a usable number but if I try to use a decimal point in the number and convert it to a double, it wont work because the decimal wont read into the (char)System.in.read();
    Anyone have a suggestion ?

    Hope this helps - although haven't tried out your code.
    System.in.read() returns the next byte of information in the buffer, if the buffer is empty it'll prompt for input (passing control back to hardware/OS). Say the user types 10.56 and presses return - now the buffer has the information 10.56 plus a LF(line-feed) and and a CR(carriage return) character (this is how it is from DOS anyway) and control is passed back to your program which gets only the first byte of information from the buffer, which in this case would represent the character '1', only it doesnt get back the character '1', it gets an int type which represents the byte of information which represented the character '1' to your hardware/OS system (which I believe is decided by the machine local encoding system).
    By casting this int to a char by the expression
    (char) System.in.read()
    its converted to the original character that the int represented from the buffer
    If you were using System.in.read() only you would have to reconstruct the input as a String by concatenating the char's one by one only ignoring the last 2 bytes of the buffer (which captured the LF and CR).
    Say you had the resulting String from the above reconstruction in the variable s1,
    you could then attempt to convert the resulting String to a floating-point type (say a double) using
    d = Double.parseDouble(s1)
    where d was a double type (as mentioned by abnormal)
    You'd have to put this in a try/catch statement because the user could type something invalid like 10.6a5
    which would cause the parseDouble() method to throw an exception which unless you handle it yourself will cause your program to abend with a NumberFormatException.
    This all seems to be a lot of hard work for input apparently so simple, which is why abnormal suggest using a BufferedReader to overcome the problem of 'manually' stripping the CR and LF from the input leaving you with just a String. I must admit I'm not sure of why abnormal's code wouldn't work for you. But I thought I'd post this anyway because you might find the background info helpful.

  • SAPUI5 oData Read function

    Hi,
    I'm currently creating an application which binds odata from a thirds party source to a local application.
    Using my odata model, I;m trying to bind the receive data to a form control. I tried using odata model read function, like below:
    this.odataModel = new sap.ui.model.odata.ODataModel("XXXXXX/SAMPLEFLIGHT/");
                 var form2 = sap.ui.getCore().byId("Form2");
                 // insert url parameters
                 this.odataModel.read("/FlightCollection(carrid='"+param1"',connid='"+param2+"',fldate=datetime'2013-05-01T00%3A00%3A00')",
                  null,
                  null,
                  false,
                  function(oData, oResponse){
                  // create JSON model
                  var oODataJSONModel =  new sap.ui.model.json.JSONModel();
                  // set the odata JSON as data of JSON model
                  oODataJSONModel.setData(oData);
                  // store the model
                  form2.setModel(oODataJSONModel, "localModel");
                  console.log(form2.getModel("localModel")); //successful output
    I was able to retrieve the odata, but when I try to display it on my form, the output is blank, below is my view file:
    var oForm1 = new sap.ui.layout.form.Form("Form2",{
           title: new sap.ui.core.Title({text: "Flight Details", tooltip: "Flight Details"}),
           layout: oLayout1,
           formContainers: [
                new sap.ui.layout.form.FormContainer("F2C1",{
                     title: "Flight Details",
                     formElements: [
                          new sap.ui.layout.form.FormElement({
                               label: new sap.ui.commons.Label({text:"Carrier ID"}),
                               fields: [
                                         new sap.ui.commons.TextField({
                                                 placeholder: "Please input carrier ID",
                                                   value: "{carrid}"
                     ], // end of form elements
    I'm sure about the path, since there are no errors generated, and the path is a direct child from the root entry. My question is, what am I missing on odata read function, and how do I properly bind the retrieved data to the form control?
    Thanks in advance!
    Gin

    Hi All,
    Already solved the issue, by investigating the odata property of my model.
    It seems that when JSONModel on odata read function, the root needs an additional "/" for the binding path.
    For example, my recent path:
    value: "{carrid}"
    will now be accessed via
    value: "{/carrid}"
    I hope this will help you regarding same issue.
    Thanks,
    Gin

  • Help with the MIDI read function

    Since my last post, I have gotten NI LabVIEW 8.5 and DSP module 2.5.  Using the MIDI read function I was able to get it to read from MIDI-Yoke and plot onto some graphs.
    My problem, however, is that I'm not sure how exactly the MIDI file is being read.  The DSP module update files say that the information is sent as an array of 5 notes.  This is clear to see that it is reading in these 5 values.  When I plot wire the MIDI read to a graph however and/or output through a DSP board, It seems as though I am only getting one of those values.
    Can anyone tell me if I am doing anything wrong or how to get all the values from the MIDI read plotted and outputed.
    Thanks

    Attached is a screenshot of my front panel.
    Yes it seems as the array is being read in through the MIDI read (all 5 values are showing up).  On the graphs, I suppose it would be all five values plotted at once.  This makes sense to me, and what I initially thought.  What made me skeptical of the function was that when I outputted the signal, I didn't hear the same sound as was being inputed.  As I previously mentioned, I could only hear a really high pitched sound, that was the rythm of the particular MIDI file.  It wasn't the original sound.  (I was testing the output.  I would like to add synths, filters, etc. and be able to output this so that the changes can be heard, not just seen on graphs)
    Thanks for the help,
    Joeyio
    Attachments:
    simple_MIDI Read.jpg ‏174 KB

  • 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.

  • Read in Binary form in VISA read function

    Dear All,
    I have connected my Device to the serial Port. and data read from the buffer is stored in text format. I want to view the data in binary format .
    Actually, i have performed the same function in Visual Basic. there also if i view the data in text format, it shows some junk values. but if i view the data in binary, it shows the actual data coming from the instrument .
    I dont know how to modify the VISA read function. can any one pls tell me how can i read the data in binary format?
    Thanks
    Ritesh

    Oops!  No it didn't.
    Lab VIEW 2012 (if that makes a dif)
    I'm using the VISA Read function to take ADC readings in from a microcontroller.  The VISA Read function outputs the data as a string.  Easy to convert the string to U8, either with the conversion function or type cast function, and works great except for a tiny corner case when the ADC reading is zero.  The VISA Read function treats the 8-bit zero reading as a null character and strips it out.
    Apparently, since this is done by the VISA Read function as it's building the string, type casting and or converting the output string from the VISA Read function doesn't "bring the zeros back".
    I've tried setting the VISA property "Discard NUL Characters" to false, and that didn't seem to help.
    My current work around is just to never have the micro send a zero ADC reading. 
    Anyway, I'm a Lab VIEW noob, so while this isn't essential to my project, I remain curious about how to send Lab VIEW serial data that isn't automatically considered characters, thrown into a string with all the zeros stripped out.
    Regards,
    Who

  • 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.

  • DAQMx Write und read function

    Hello,
    I want to use DAQMx functions for my projekt.. but I do not understand one thing. Wenn I have a differnet Input should I use DAQmx write  and for the Output DAQMX Read? or better said what is the different betwen DAQmx write and Read, When I can used write and read? 

    Hi nichts,
    use the DAQmx read function, if you want to acquire a signal from your card. If you use a differential input, you also use the same vi (DAQmx read) and change the "input terminal configuration" on the DAQmx Create virtual channel vi to differential mode.
    If you want to generate data from your PC and output those data over your DAQ-Card, use the DAQmx write VI.
    If you use the DAQmx driver the first time, I would recommend you the following internet page:
    Learn 10 Functions in NI-DAQmx and Handle 80 Percent of Your Data Acquisition Applications - Developer Zone - National Instruments
    http://www.ni.com/white-paper/2835/en
    You will find all necessary information about the important part of the DAQmx driver on this page.

  • HT4753 I have a very simple question: how do I view where Lion has autosaved my current version to (without the convoluted route of using finder)? In days gone by i'd simply use the save as function to see where it was being saved.

    I have a very simple question: how do I view where Lion has autosaved my current version to (without the convoluted route of using finder)? In days gone by i'd simply use the save as function to see where it was being saved.

    It's actually even easier than using Save As to see the full path to the currently open document. Just do a "Secondary click" on the document title in its window's title bar.
    Like you, I relied upon Save As my whole life to check a file's location and considered it a must-have capability. Turns out it's even faster to use the single-click method to reveal the full path to the open document. It displays the entire path to the current document starting from the level of your Mac, and works for files stored on drives as well as iCloud.
    If you're not sure how to do a secondary click, go into System Preferences, select Trackpad, Point & Click to find the current preference for secondary click on your Mac. If you happen to have a mouse with more than one button, it's probably the right button. As a trackpad user, I check the box to "Click or tap with two fingers," so a simple two finger tap on the title of an open document reveals its full path. This feature actually has been around for a very long time.
    Note that this is not the same thing as the Autosave and Versions menu, which is exposed using a little drop down triangle to the right of the title. There is no visual clue for the presence of this feature - you just have to know it's there, probably because this feature goes all the way back to pre-OS X days.

  • HT4759 I am trying to set up icloud on my Macbook. I was using the step by step guide on your site but when I open system perferences I do not have the icloud icon under internet and wireless. How do I get it?

    I am trying to set up icloud on my macbook, I was using the step by step guide on the site but when I try go into system perfences in there is no icloud icon under internet and wireless. How do I get it?

    This is presumably because you are running an earlier system than Lion. (Please always post your system when you have a question.)
    The minimum requirement for iCloud is Lion 10.7.5 (Mavericks preferred): the iCloud Preference Pane does not appear on earlier systems - the MobileMe pane appears on Lion and earlier but is non non-functional - you cannot now open or access a MobileMe account.
    To make use of iCloud you will have to upgrade your Mac to Lion or Mavericks, provided it meets the requirements.
    The requirements for Lion are:
    Mac computer with an Intel Core 2 Duo, Core i3, Core i5, Core i7, or Xeon processor
    2GB of memory
    OS X v10.6.6 or later (v10.6.8 recommended)
    7GB of available space
    Lion is available in the Online Apple Store ($19.99). Mountain Lion (10.8.x) is also available there at the same price but there seems little point as the system requirements are the same for Mavericks (10.9.x) - which is free - unless you need to run specific software which will run on Mountain Lion only.
    The requirements for Mountain Lion and Mavericks are:
    OS X v10.6.8 or later
    2GB of memory
    8GB of available space
      and the supported models are:
    iMac (Mid 2007 or newer)
    MacBook (Late 2008 Aluminum, or Early 2009 or newer)
    MacBook Pro (Mid/Late 2007 or newer)
    Xserve (Early 2009)
    MacBook Air (Late 2008 or newer)
    Mac mini (Early 2009 or newer)
    Mac Pro (Early 2008 or newer)
    It is available from the Mac App Store (in Applications).
      You should be aware that PPC programs (such as AppleWorks) will not run on Lion or above; and some other applications may not be compatible - there is a useful compatibility checklist at http://roaringapps.com/apps:table
      If you are running Leopard on an Intel Mac you will have to upgrade to Snow Leopard to access the Mac App Store - it's available in the online Apple Store. However if you have a PPC Mac you cannot run Snow Leopard and cannot proceed further.

  • I cannot open Adobe photoshop CS2 which I was using 10 days ago.  Can I restore the system to before 10 days, so it will work again?

    I cannot open Adobe photoshop CS2 which I was using 10 days ago.  Can I restore the system to before 10 days, so it will work again?

    The hatter wrote:
    Rosetta can have a 2GB RAM "tax" to manage PowerPC code as well as how that affects performance.
    I think real world performance shows both statements to be wrong; consider this:
    If that were the case, how come Apple does not include that information in its Snow Leopard installation requirements, since Rosetta is an optional install?
    Also, running a PowerPC app on an 2011 i7 Mac with Snow Leopard will run faster than running that PowerPC app on a PowerPC Mac.

  • Safari will no longer open.  I was using firefox until I could find a fix for safari.  I made the mistake of changing my default search to firebox later for convenience and now I can't open my system preference or many safari or apple linked files.

    Safari will no longer open. It just goes back to my desktop.  When I right click on the safari icon in my dashboard it says it is open.  I was using firefox until I could find a fix for safari.  I made the mistake of changing my default search to firebox later for convenience and now I can't open my system preference or many safari or apple linked files. Some of my emails from trusted sites won't open and does the same thing. 
    I upgraded my original system from 10.4.11 to I believe 10.6. something about a year or so ago.  I thought about re installing my safari app but when I go to open anything connected to safari my screen goes back to the desktop.  I cant open any files that I have on my desktop that I set up through safari, like my banking program. Prior to changing system preference to safari default I was able to open those files and now I can't get into change it back.  Can you guide me through this?
    Thanks,
    Betty

    Try running the 10.6.8 combo update.
    10.6.8 Combo Updater
    System Preferences or Safari Preferences?
    Do a backup.
    Quit the application.
    Go to Finder and select your user/home folder. Select Library. Then go to Preferences/com.apple.Safari.plist. Move the .plist to your desktop.
    Restart the computer, open the application and test. If it works okay, delete the plist from the desktop.
    If the application is the same, return the .plist to where you got it from, overwriting the newer one.

  • When accessing shared folder - 'You might not have permission to use this network resource" .. A device attached to the system is not functioning

    On a Windows 2008 R2 server that had been working fine, all of a sudden some shared folders became inaccessible.  Clicking on them returned the following: "<Folder> is not accessible.  You might not have permission to use this network
    resource.  A device attached to the system is not functioning."
    If I create another share with a different name for that same folder, it works fine.  If I delete the original share then recreate it with the same name, I get the same error.  However, if I right click on the problematic share and select 'map
    network drive' that works.  So this would not appear to be a permission issue.
    I discovered this problem because the path for mapping the home folder as a property of their AD account stopped working.
    I have tried most of the common things found on the internet.  I've tried accessing via IP, same issue.  While I only have a couple 2003 servers, those can access this resource.
    At this point, I'm pretty much out of ideas.  Any help would be appreciated.  I also have some reports of potential issues with some printer mappings too which I will have to investigate in the morning.
    If anyone has a solution to this I would be extremely grateful.  Thank you.

    Hi,
    Can you access the shard folder locally? Is a specific server cannot access the shared folder? Please try to Boot your server in Clean Mode to check if some third-party software cause the issue.
    How to perform a clean boot in Windows
    http://support.microsoft.com/kb/929135
    Best Regards,
    Mandy
    If you have any feedback on our support, please click
    here .
    We
    are trying to better understand customer views on social support experience, so your participation in this
    interview project would be greatly appreciated if you have time.
    Thanks for helping make community forums a great place.

Maybe you are looking for

  • How to use read_text function module

    Hi how to use read_text function module to read purchase order header text .what are all tht things to pass in ID,Name and Object thanks, Mahe

  • Why can't I use the "Gumtree" website properly in Firefox?

    Every time I try to use "Gumtree" Australia, Firefox becomes sluggish and lags very badly, and when I try to click on an ad to view it, something comes up telling me that a script has stopped working, and then Firefox crashes. Firefox has been laggin

  • Extreme database

    Would you guide me where to download the free extreme database for learning Crystal Report Designer? Thanks

  • How to Split 10.6.8 and 10.9. 5 on a 2011 Imac

    Hi Yo wizzartz out there! As i have severe problems on Logic X i´d like to split my Mac. I have 2 harddrives inside , one to backup one to "work", and a third 1 outside to backup aswell. I want to go back to 10.6.8 on the one hand to work my songs pr

  • Updating Lightswitch Apps to Target Framework 4.6

    When Framework 4.6 launches will we be able to upgrade or migrate our projects to target dotNET framework 4.6 or will we need to rebuild our solutions?