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.
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?
Re: Gettting whitespace back from Scanner.
can you not do something like this,
Code :
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
Code :
System.getProperty("line.separator")
and ill not be skipping tabs, spaces etc
Regards,
Chris
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.