aspose file tools*
The moose likes Beginning Java and the fly likes Skip Line/Pattern with Scanner class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Skip Line/Pattern with Scanner class" Watch "Skip Line/Pattern with Scanner class" New topic
Author

Skip Line/Pattern with Scanner class

Viv Singh
Ranch Hand

Joined: Nov 08, 2008
Posts: 73
Hi,

I have the following content in a file:

Drives
********
cdr LITEON DVD-ROM LTD163 GDHA
cdr HL-DT-ST CD-RW GCE-8400B B104

My aim is to extract the information of both drives and I have written the following code:



I use s.nextLine() to skip the pattern *******, I tried to use the built in method skip as follows:

s.skip("*******");

but that did not work. Am I doing something wrong?

thanks in advance.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

* is part of regular expressions, so you will need to escape it with a \ (which again must be escaped because it is part of a string):
Of course, this can be shortened by using the count operator:
See Pattern for more information on regular expressions.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Skip Line/Pattern with Scanner class