Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Use of scanner to return white space between the tokens

  1. #1
    Junior Member
    Join Date
    May 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Use of scanner to return white space between the tokens

    I'm trying to read in a .java file then output it with highlighted keywords etc. as an HTML file. I obvoiusly want to keep the formating but don't know how to use Scanner to return the whitspace between the tokens.

    is it possible or do i need to try another another approach.


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Gettting whitespace back from Scanner.

    Hello Alysosh,

    Welcome to the Java Programming Forums

    I'm unsure what you mean by returning the whitespace between the tokens?
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  3. #3
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: Gettting whitespace back from Scanner.

    can you not do something like this,
    Scanner s = new Scanner(new FileReader("test.java")); // handle exceptions
    while(s.hasNext()){
      s.readLine(); // do something with this value...like search it for words etc
    }
    that way you know that the only white space you are skipping is equal to
    System.getProperty("line.separator")
    and ill not be skipping tabs, spaces etc

    Regards,
    Chris

  4. #4
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Gettting whitespace back from Scanner.

    Yeah thats what I was going to suggest Chris. You can read it in line by line and write it out in exactly the same way in the same format.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

Similar Threads

  1. Reading user input from the console with the Scanner class
    By JavaPF in forum Java SE API Tutorials
    Replies: 3
    Last Post: September 7th, 2011, 03:09 AM
  2. [SOLVED] Enhancement in program of removing whitespace from text file
    By John in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: April 27th, 2009, 09:36 AM
  3. [SOLVED] Problem in Coin-counter with scanner class
    By coccoster in forum File I/O & Other I/O Streams
    Replies: 6
    Last Post: March 25th, 2009, 08:46 AM
  4. Replies: 1
    Last Post: May 13th, 2008, 08:08 AM