How do I read a character and advance the scanner to the next one?

Hi,
I'm writing a lexical and grammar analyzer and I don't usually program in Java. I have a method that reads one character and then parses it. The problem is that it keeps reading the same character over and over again, so my program gets stuck in an infinite loop.
How do I make it so that BufferedReader advances to the next character in the string?
Here is the code so far:
public static void getChar()
            throws FileNotFoundException, UnsupportedEncodingException, IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader
                (new FileInputStream(inputFileName), Charset.forName("UTF-8")));
        int c;
        if ((c = reader.read()) != -1){
            if (c != 32)
                nextChar = (char) c;
            if (Character.isLetter(nextChar))
                charClass = LETTER;
            else if (Character.isDigit(nextChar))
                charClass = DIGIT;
            else
                charClass = UNKNOWN;
        else{
            charClass = EOF;
            //System.out.println("Next Token is: RES_WORD. Next lexeme is: EOF.");
    } //end getChar.At first I just had a while loop, but I want this method to be called from another method and so I didn't think the while loop worked. Is there a better way?
Help is much appreciated.
EDIT: By the way, I don't want to read tokens. I need it to be characters. And it doesn't have to be BufferedReader. I'm open to suggestions.
EDIT2: While I don't want to read tokens, if it's the simplest way then I'm open to it. The scanner class would work for that I guess, but then I would have to do a charAt stuff. I'm open to your insight.
Edited by: RommelR on Feb 25, 2010 8:39 AM
Edited by: RommelR on Feb 25, 2010 9:00 AM

DrClap wrote:
Every time you call that method, you open a new BufferedReader on the file and read the first character from it. So yes, you always get the same character. Solution: Don't open the BufferedReader in that method. Open it somewhere else, just once, and use it in that method.Thanks. That was stupid of me.

Similar Messages

  • How old licenses migration during basic and advanced cisco ise?

    Hello,
    How old licenses migration during basic and advanced cisco ise?
    Regards,
    Alvaro

    Hi,
    What do you mean by migration? you are migrating to another hardware? or you are upgrading from basic to advanced license?
    here is the install/upgrade process:
    http://www.cisco.com/en/US/docs/security/ise/1.1/user_guide/ise_man_license.html#wp1059946
    If you are migrating from one device to another I think you need to use this link:
    https://tools.cisco.com/SWIFT/LicensingUI/Home
    HTH
    Amjad

  • I have a new computer.  How do I get my books and apps to show in the library on my itunes?

    I have a new computer.  How do I get my books and apps to show in the library on my itunes?

    Copy the ENTIRE iTunes folder from the old computer to the new computer.

  • I want to transfer an audiobook and a movie from my MacBook Pro to my iPhone 4S, and can't figure out how.  I went to "Help" and it said after connecting the two devices I should "Click Apps," but I can't find anything labeled "Apps" to click.  Help?!!

    I want to transfer an audiobook and a movie from my MacBook Pro to my iPhone 4S, and can't figure out how.  I went to "Help" and it said after connecting the two devices I should "Click Apps," but I can't find anything labeled "Apps" to click.  Help?!!

    If you have iTunes 11 on your Mac then you can enable the left-hand sidebar via option-command-S, that might make it easier to navigate.
    Connect the phone to your Mac and select it on that left-hand sidebar, and on the right-hand side of the screen there should be a series of tabs which you can use to select what to sync to the phone. If it's an audiobook then it should appear on the Books tab for selecting/syncing, and films will be on the Movies tab. When you've got the audiobook on your phone you should get an Audiobooks option in the Music app (you might need to tap the '...' tab at the bottom of the Music app to see it).

  • How can I listen to itunes and play a game at the same time on my ipad 4?

    How can I listen to itunes and play a game at the same time on my ipad 4? This means I need to run 2 apps at the same time itunes and my game.  The game has its own sound control so I can turn off its sound while i listen to itunes tracks.  But I don't know how to set it up so the ipad does both.

    Anytime you open an app that has a persistant sound stream - a movie, a podcast, some games - it will overide the music app's stream. nothiong you can do to change it.

  • How do I backup my iphone to a computer when every time I plug it into the computer, it starts syncing it to itunes or trying to download itunes?  How do I back it up and where do I find the backup?

    How do I backup my iphone to a computer when every time I plug it into the computer, it starts syncing it to itunes or trying to download itunes?  How do I back it up and where do I find the backup?

    The backup does not include any itunes content. NO apps, music,etc
    You can transfer itunes purchases from iphone to computer:  File>Transfer Purchases
    You need to copy everything from your backup copy of your old computer to your new computer.

  • How to restore my icloud backup and where can I find the setup assisant in my new ipad

    Dear Sir
    Can you help my on how to restore my icloud backup and where can I find the setup assisant in my new ipad?
    Thanks and Regards,
    Clare

    iPhone User Guide (For iOS 6.1 Software)

  • How can i download photoshop elements and premiere elements 10 using the serial number not the cd?

    How can i download photoshop elements and premiere elements 10 using the serial number not the cd?
    I tried downloading the trial elements 11 and entering the serial number but it wouldn't work, i cannot find a trial for elements 10.
    Thanks

    http://prodesigntools.com/photoshop-elements-10-direct-download-links-pse-premiere-pre.htm l
    Follow the instructions on that page carefully before you click the download link.

  • How do you shadow a phone and is it possible for the person your shadowing to be able to tell?

    How do you shadow your phone and is it possible for the person you are shadowing to tell?

    Shadow? Are you referring to tracking the phone? If it is your phone, how are you tracking it? Are you talking about a stolen device?

  • How do I remove server os and install normal os?  The computer has never been used as a server.  I only purchased the server version because of two internal hard drives.

    How do I remove server os and install normal os?  The computer has never been used as a server.  I only purchased the server version because of two internal hard drives.

    If you want to just disable the Server aspect, this should work for both Lion and Mountain Lion...
    http://support.apple.com/kb/HT4827
    If you want to completely start over, backup your /Users and /Applications directories and re-install the client OS.

  • I have and Ipod touch, and new computer. How can i add all purchased and non purchased songs? The old computer with the original library is dead. HELP

    I have an  ipod touch 3rd  generation and a new computer. How can i add all purchased and non purchased songs into the new computers itune library? The old computer is dead! Will not even turn on. Help!!!!!!!! I'm going crazy.

    Look into downloading some type of iRip software! Allows you to transfer music from iPod to iTunes.

  • How can you listen to music and play a game at the same time?

    How can you listen to music and play a game at the same time?
    I am playing music, by starting the Crash Baandicoot Nitro Kart 3D game it shuts off the music playing. Is there a way around this?
    It seems like this should be possible.
    Message was edited by: RuthlessVengeance
    Message was edited by: RuthlessVengeance

    Select the music play list you want to listen to and start it playing. Go back to the home screen and start the app you want to use, music will stop. Press the home button two time quickly and it will bring up a simple control for controling the music. This works for me with all of the apps I have purchased including games. Just a note you can pull up the same music control if the iPod is a sleep and locked by pressing the button three times quickly.
    Mike

  • HT4623 I am on iOS 4, how do I update to iOS5 and later as several of the apps are not working now. Thank you

    I am on iOS 4, how do I update to iOS5 and later as several of the apps are not working now. Does anyone know how to upgrade to at least iOS5. I am on version 4.3.5 now and it is a iPad2 16M. Thank you.

    Upgrading iOS
       1. How to update your iPhone, iPad, or iPod Touch
       2. iPhone Support
       3. iPod Touch Support
       4. iPad Support
         a. Updating Your iOS to Version 6.0.x from iOS 5
              Tap Settings > General > Software Update
         If an update is available there will be an active Update button. If you are current,
         then you will see a gray screen with a message saying your are up to date.
         b. If you are still using iOS 4 — Updating your device to iOS 5 or later.
         c. Resolving update problems
            1. iOS - Unable to update or restore
            2. iOS- Resolving update and restore alert messages

  • If when I go holiday and my iPad goes through the scanner at the airport will it make my iPad stop working

    I am going to a holiday soon and I heard that electronic items get faulty when they go through the scanner at the airport also my brother had a android tablet (and I know android tablets are super faulty and bad quality unlike apple tablets) and when we arrived to our destination the tablet just shut down and we did all the checks (if the battery is dead) and it just shut down so I am worried it will happen to my ipad

    If you've turned VoiceOver on then see if triple-clicking the home button turns it off, and then change what Settings > General > Accessibility > Triple-Click Home is set to.
    Otherwise, via 'the touch to select double-tap to activate' process you need to go into Settings > General > Accessibility > VoiceOver and turn it off
    The manual (http://support.apple.com/manuals/#ipad) also says that you should be able to switch voice-over off by connecting to your computer's iTunes :
    Turn VoiceOver on or off in iTunes: Select iPad in the iTunes sidebar. In the Options section of the Summary pane, click Configure Universal Access. Select VoiceOver, then click OK.
    So select Configure Universal Access at the bottom of the Summary tab and set Seeing to Neither

  • How can I read a template and differentiate if it is a pattern matching template or a geometric matching template?

    Hey all,
    I would like to know how can I read a template´s information to know if it is a pattern macthing or a geometric matching template? 
    In my code, users provide templates and the algorithm must match them using pattern matching or geometric matching depending on the template.
    At the moment I am doing it by including a P or a G in the name of the file, but I would like to avoid this and read the information from the file.
    Any ideas?
    Thanks in advance,
    Esteban
    Solved!
    Go to Solution.

    Hey Esteban,
    you can use the VI "IMAQ Is Vision Info Present 2 VI" to reice the information:
    IMAQ Is Vision Info Present 2 VI - NI Vision 2011 for LabVIEW Help - National Instruments
    http://zone.ni.com/reference/en-XX/help/370281P-01/imaqvision/imaq_is_vision_info_present_2/
    Take a look at the attached VI
    Stephan
    Attachments:
    Determine Pattern type.zip ‏13 KB

Maybe you are looking for

  • USB Keyboard just stopped being recognised

    Hi I have an iMac 2.8 i7 that is running os x 10.6.8 I have an Apple USB keyboard connected to it and everything has worked fine for several years I booted up the iMac today and was greeted by the Bluetooth Keyboard Setup - no wireless keyboard conne

  • Call popup with ITS

    Hello, I am trying to modify a specific popup generation in order to send back to SAP that this popup is definetely closed. I have currently an error when opening this popup more than 10 times. This situation occurs when we assign cost centers in ite

  • Changing Unix Time Stamp

    Hi everyone, Am trying to change the unix time to normal date format. am using *"<?xdoxslt:ora_format_date_offset('1970-01-01', DUE_T div 86400, ??)?>"*+ But when I try to run the report (with sample xml), it is showing me the below error: "Caused by

  • Arch Linux User Creation Section

    I think there should be some sort of Arch Linux software/script/multimedia section in this board.  Like the various splash screens, wallpapers, scripts, and other related software/things that the users of Arch Linux have created.  It isn't very easy

  • Working with AVCHD from a Panasonic SD60

    Good afternoon, I've noticed that when I import a video (AVCHD, 1080i50) that the resolution changes to 960x540 when certain effects are added whilst editing, is there a way to avoid this as I would like to be able to publish my movies in full HD? Ma