File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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: 19651
    
  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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Skip Line/Pattern with Scanner class
 
Similar Threads
how exactly can i make out if a file in linux has just been updated or has been replaced.
Scanner skip
Parse Command file
"parsing file"
Passing values from method1 to method2