Java Doc for Scanner.java in  » 6.0-JDK-Core » Collections-Jar-Zip-Logging-regex » java » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Home
Java Source Code / Java Documentation
1.6.0 JDK Core
2.6.0 JDK Modules
3.6.0 JDK Modules com.sun
4.6.0 JDK Modules com.sun.java
5.6.0 JDK Modules sun
6.6.0 JDK Platform
7.Ajax
8.Apache Harmony Java SE
9.Aspect oriented
10.Authentication Authorization
11.Blogger System
12.Build
13.Byte Code
14.Cache
15.Chart
16.Chat
17.Code Analyzer
18.Collaboration
19.Content Management System
20.Database Client
21.Database DBMS
22.Database JDBC Connection Pool
23.Database ORM
24.Development
25.EJB Server
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Net
51.Parser
52.PDF
53.Portal
54.Profiler
55.Project Management
56.Report
57.RSS RDF
58.Rule Engine
59.Science
60.Scripting
61.Search Engine
62.Security
63.Sevlet Container
64.Source Control
65.Swing Library
66.Template Engine
67.Test Coverage
68.Testing
69.UML
70.Web Crawler
71.Web Framework
72.Web Mail
73.Web Server
74.Web Services
75.Web Services apache cxf 2.2.6
76.Web Services AXIS2
77.Wiki Engine
78.Workflow Engines
79.XML
80.XML UI
Java Source Code / Java Documentation » 6.0 JDK Core » Collections Jar Zip Logging regex » java.util 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   java.util.Scanner

Scanner
final public class Scanner implements Iterator<String>(Code)
A simple text scanner which can parse primitive types and strings using regular expressions.

A Scanner breaks its input into tokens using a delimiter pattern, which by default matches whitespace. The resulting tokens may then be converted into values of different types using the various next methods.

For example, this code allows a user to read a number from System.in:

 Scanner sc = new Scanner(System.in);
 int i = sc.nextInt();
 

As another example, this code allows long types to be assigned from entries in a file myNumbers:

 Scanner sc = new Scanner(new File("myNumbers"));
 while (sc.hasNextLong()) {
 long aLong = sc.nextLong();
 }

The scanner can also use delimiters other than whitespace. This example reads several items in from a string:

 String input = "1 fish 2 fish red fish blue fish";
 Scanner s = new Scanner(input).useDelimiter("\\s*fish\\s*");
 System.out.println(s.nextInt());
 System.out.println(s.nextInt());
 System.out.println(s.next());
 System.out.println(s.next());
 s.close(); 

prints the following output:

 1
 2
 red
 blue 

The same output can be generated with this code, which uses a regular expression to parse all four tokens at once:

 String input = "1 fish 2 fish red fish blue fish";
 Scanner s = new Scanner(input);
 s.findInLine("(\\d+) fish (\\d+) fish (\\w+) fish (\\w+)");
 MatchResult result = s.match();
 for (int i=1; i<=result.groupCount(); i++)
 System.out.println(result.group(i));
 s.close(); 

The default whitespace delimiter used by a scanner is as recognized by java.lang.Character . java.lang.Character.isWhitespace(char) isWhitespace . The Scanner.reset method will reset the value of the scanner's delimiter to the default whitespace delimiter regardless of whether it was previously changed.

A scanning operation may block waiting for input.

The Scanner.next and Scanner.hasNext methods and their primitive-type companion methods (such as Scanner.nextInt and Scanner.hasNextInt ) first skip any input that matches the delimiter pattern, and then attempt to return the next token. Both hasNext and next methods may block waiting for further input. Whether a hasNext method blocks has no connection to whether or not its associated next method will block.

The Scanner.findInLine , Scanner.findWithinHorizon , and Scanner.skip methods operate independently of the delimiter pattern. These methods will attempt to match the specified pattern with no regard to delimiters in the input and thus can be used in special circumstances where delimiters are not relevant. These methods may block waiting for more input.

When a scanner throws an InputMismatchException , the scanner will not pass the token that caused the exception, so that it may be retrieved or skipped via some other method.

Depending upon the type of delimiting pattern, empty tokens may be returned. For example, the pattern "\\s+" will return no empty tokens since it matches multiple instances of the delimiter. The delimiting pattern "\\s" could return empty tokens since it only passes one space at a time.

A scanner can read text from any object which implements the java.lang.Readable interface. If an invocation of the underlying readable's java.lang.Readable.read method throws an java.io.IOException then the scanner assumes that the end of the input has been reached. The most recent IOException thrown by the underlying readable can be retrieved via the Scanner.ioException method.

When a Scanner is closed, it will close its input source if the source implements the java.io.Closeable interface.

A Scanner is not safe for multithreaded use without external synchronization.

Unless otherwise mentioned, passing a null parameter into any method of a Scanner will cause a NullPointerException to be thrown.

A scanner will default to interpreting numbers as decimal unless a different radix has been set by using the Scanner.useRadix method. The Scanner.reset method will reset the value of the scanner's radix to 10 regardless of whether it was previously changed.

Localized numbers

An instance of this class is capable of scanning numbers in the standard formats as well as in the formats of the scanner's locale. A scanner's initial locale is the value returned by the java.util.Locale.getDefault method; it may be changed via the Scanner.useLocale method. The Scanner.reset method will reset the value of the scanner's locale to the initial locale regardless of whether it was previously changed.

The localized formats are defined in terms of the following parameters, which for a particular locale are taken from that locale's java.text.DecimalFormat DecimalFormat object, df, and its and java.text.DecimalFormatSymbols DecimalFormatSymbols object, dfs.

LocalGroupSeparator   The character used to separate thousands groups, i.e., dfs. java.text.DecimalFormatSymbols.getGroupingSeparatorgetGroupingSeparator()
LocalDecimalSeparator   The character used for the decimal point, i.e., dfs. java.text.DecimalFormatSymbols.getDecimalSeparatorgetDecimalSeparator()
LocalPositivePrefix   The string that appears before a positive number (may be empty), i.e., df. java.text.DecimalFormat.getPositivePrefixgetPositivePrefix()
LocalPositiveSuffix   The string that appears after a positive number (may be empty), i.e., df. java.text.DecimalFormat.getPositiveSuffixgetPositiveSuffix()
LocalNegativePrefix   The string that appears before a negative number (may be empty), i.e., df. java.text.DecimalFormat.getNegativePrefixgetNegativePrefix()
LocalNegativeSuffix   The string that appears after a negative number (may be empty), i.e., df. java.text.DecimalFormat.getNegativeSuffixgetNegativeSuffix()
LocalNaN   The string that represents not-a-number for floating-point values, i.e., dfs. java.text.DecimalFormatSymbols.getNaNgetNaN()
LocalInfinity   The string that represents infinity for floating-point values, i.e., dfs. java.text.DecimalFormatSymbols.getInfinitygetInfinity()

Number syntax

The strings that can be parsed as numbers by an instance of this class are specified in terms of the following regular-expression grammar, where Rmax is the highest digit in the radix being used (for example, Rmax is 9 in base 10).

NonASCIIDigit  :: = A non-ASCII character c for which java.lang.Character.isDigit Character.isDigit (c) returns true
 
Non0Digit  :: = [1-Rmax] | NonASCIIDigit
 
Digit  :: = [0-Rmax] | NonASCIIDigit
 
GroupedNumeral  ::
= (  Non0Digit Digit? Digit?
LocalGroupSeparator Digit Digit Digit )+ )
 
Numeral  :: = ( ( Digit+ ) | GroupedNumeral )
 
Integer  :: = ( [-+]? ( Numeral ) )
| LocalPositivePrefix Numeral LocalPositiveSuffix
| LocalNegativePrefix Numeral LocalNegativeSuffix
 
DecimalNumeral  :: = Numeral
| Numeral LocalDecimalSeparator Digit*
| LocalDecimalSeparator Digit+
 
Exponent  :: = ( [eE] [+-]? Digit+ )
 
Decimal  :: = ( [-+]? DecimalNumeral Exponent? )
| LocalPositivePrefix DecimalNumeral LocalPositiveSuffix Exponent?
| LocalNegativePrefix DecimalNumeral LocalNegativeSuffix Exponent?
 
HexFloat  :: = [-+]? 0[xX][0-9a-fA-F]*\.[0-9a-fA-F]+ ([pP][-+]?[0-9]+)?
 
NonNumber  :: = NaN | LocalNan | Infinity | LocalInfinity
 
SignedNonNumber  :: = ( [-+]? NonNumber )
| LocalPositivePrefix NonNumber LocalPositiveSuffix
| LocalNegativePrefix NonNumber LocalNegativeSuffix
 
Float  :: = Decimal
| HexFloat
| SignedNonNumber

Whitespace is not significant in the above regular expressions.
version:
   1.34, 06/11/07
since:
   1.5




Constructor Summary
public  Scanner(Readable source)
     Constructs a new Scanner that produces values scanned from the specified source.
public  Scanner(InputStream source)
     Constructs a new Scanner that produces values scanned from the specified input stream.
public  Scanner(InputStream source, String charsetName)
     Constructs a new Scanner that produces values scanned from the specified input stream.
public  Scanner(File source)
     Constructs a new Scanner that produces values scanned from the specified file.
public  Scanner(File source, String charsetName)
     Constructs a new Scanner that produces values scanned from the specified file.
public  Scanner(String source)
     Constructs a new Scanner that produces values scanned from the specified string.
public  Scanner(ReadableByteChannel source)
     Constructs a new Scanner that produces values scanned from the specified channel.
public  Scanner(ReadableByteChannel source, String charsetName)
     Constructs a new Scanner that produces values scanned from the specified channel.

Method Summary
public  voidclose()
     Closes this scanner.

If this scanner has not yet been closed then if its underlying also implements the java.io.Closeable interface then the readable's close method will be invoked.

public  Patterndelimiter()
     Returns the Pattern this Scanner is currently using to match delimiters.
public  StringfindInLine(String pattern)
     Attempts to find the next occurrence of a pattern constructed from the specified string, ignoring delimiters.
public  StringfindInLine(Pattern pattern)
     Attempts to find the next occurrence of the specified pattern ignoring delimiters.
public  StringfindWithinHorizon(String pattern, int horizon)
     Attempts to find the next occurrence of a pattern constructed from the specified string, ignoring delimiters.
public  StringfindWithinHorizon(Pattern pattern, int horizon)
     Attempts to find the next occurrence of the specified pattern.

This method searches through the input up to the specified search horizon, ignoring delimiters.

public  booleanhasNext()
     Returns true if this scanner has another token in its input.
public  booleanhasNext(String pattern)
     Returns true if the next token matches the pattern constructed from the specified string.
public  booleanhasNext(Pattern pattern)
     Returns true if the next complete token matches the specified pattern. A complete token is prefixed and postfixed by input that matches the delimiter pattern.
public  booleanhasNextBigDecimal()
     Returns true if the next token in this scanner's input can be interpreted as a BigDecimal using the Scanner.nextBigDecimal method.
public  booleanhasNextBigInteger()
     Returns true if the next token in this scanner's input can be interpreted as a BigInteger in the default radix using the Scanner.nextBigInteger method.
public  booleanhasNextBigInteger(int radix)
     Returns true if the next token in this scanner's input can be interpreted as a BigInteger in the specified radix using the Scanner.nextBigInteger method.
public  booleanhasNextBoolean()
     Returns true if the next token in this scanner's input can be interpreted as a boolean value using a case insensitive pattern created from the string "true|false".
public  booleanhasNextByte()
     Returns true if the next token in this scanner's input can be interpreted as a byte value in the default radix using the Scanner.nextByte method.
public  booleanhasNextByte(int radix)
     Returns true if the next token in this scanner's input can be interpreted as a byte value in the specified radix using the Scanner.nextByte method.
public  booleanhasNextDouble()
     Returns true if the next token in this scanner's input can be interpreted as a double value using the Scanner.nextDouble method.
public  booleanhasNextFloat()
     Returns true if the next token in this scanner's input can be interpreted as a float value using the Scanner.nextFloat method.
public  booleanhasNextInt()
     Returns true if the next token in this scanner's input can be interpreted as an int value in the default radix using the Scanner.nextInt method.
public  booleanhasNextInt(int radix)
     Returns true if the next token in this scanner's input can be interpreted as an int value in the specified radix using the Scanner.nextInt method.
public  booleanhasNextLine()
     Returns true if there is another line in the input of this scanner. This method may block while waiting for input.
public  booleanhasNextLong()
     Returns true if the next token in this scanner's input can be interpreted as a long value in the default radix using the Scanner.nextLong method.
public  booleanhasNextLong(int radix)
     Returns true if the next token in this scanner's input can be interpreted as a long value in the specified radix using the Scanner.nextLong method.
public  booleanhasNextShort()
     Returns true if the next token in this scanner's input can be interpreted as a short value in the default radix using the Scanner.nextShort method.
public  booleanhasNextShort(int radix)
     Returns true if the next token in this scanner's input can be interpreted as a short value in the specified radix using the Scanner.nextShort method.
public  IOExceptionioException()
     Returns the IOException last thrown by this Scanner's underlying Readable.
public  Localelocale()
     Returns this scanner's locale.
public  MatchResultmatch()
     Returns the match result of the last scanning operation performed by this scanner.
public  Stringnext()
     Finds and returns the next complete token from this scanner. A complete token is preceded and followed by input that matches the delimiter pattern.
public  Stringnext(String pattern)
     Returns the next token if it matches the pattern constructed from the specified string.
public  Stringnext(Pattern pattern)
     Returns the next token if it matches the specified pattern.
public  BigDecimalnextBigDecimal()
     Scans the next token of the input as a java.math.BigDecimalBigDecimal .
public  BigIntegernextBigInteger()
     Scans the next token of the input as a java.math.BigIntegerBigInteger .
public  BigIntegernextBigInteger(int radix)
     Scans the next token of the input as a java.math.BigIntegerBigInteger .
public  booleannextBoolean()
     Scans the next token of the input into a boolean value and returns that value.
public  bytenextByte()
     Scans the next token of the input as a byte.
public  bytenextByte(int radix)
     Scans the next token of the input as a byte. This method will throw InputMismatchException if the next token cannot be translated into a valid byte value as described below.
public  doublenextDouble()
     Scans the next token of the input as a double. This method will throw InputMismatchException if the next token cannot be translated into a valid double value. If the translation is successful, the scanner advances past the input that matched.

If the next token matches the Float regular expression defined above then the token is converted into a double value as if by removing all locale specific prefixes, group separators, and locale specific suffixes, then mapping non-ASCII digits into ASCII digits via Character.digit Character.digit , prepending a negative sign (-) if the locale specific negative prefixes and suffixes were present, and passing the resulting string to Double.parseDouble Double.parseDouble .

public  floatnextFloat()
     Scans the next token of the input as a float. This method will throw InputMismatchException if the next token cannot be translated into a valid float value as described below.
public  intnextInt()
     Scans the next token of the input as an int.
public  intnextInt(int radix)
     Scans the next token of the input as an int. This method will throw InputMismatchException if the next token cannot be translated into a valid int value as described below.
public  StringnextLine()
     Advances this scanner past the current line and returns the input that was skipped. This method returns the rest of the current line, excluding any line separator at the end.
public  longnextLong()
     Scans the next token of the input as a long.
public  longnextLong(int radix)
     Scans the next token of the input as a long. This method will throw InputMismatchException if the next token cannot be translated into a valid long value as described below.
public  shortnextShort()
     Scans the next token of the input as a short.
public  shortnextShort(int radix)
     Scans the next token of the input as a short. This method will throw InputMismatchException if the next token cannot be translated into a valid short value as described below.
public  intradix()
     Returns this scanner's default radix.
public  voidremove()
     The remove operation is not supported by this implementation of Iterator.
public  Scannerreset()
     Resets this scanner.
public  Scannerskip(Pattern pattern)
     Skips input that matches the specified pattern, ignoring delimiters.
public  Scannerskip(String pattern)
     Skips input that matches a pattern constructed from the specified string.
public  StringtoString()
    

Returns the string representation of this Scanner.

public  ScanneruseDelimiter(Pattern pattern)
     Sets this scanner's delimiting pattern to the specified pattern.
public  ScanneruseDelimiter(String pattern)
     Sets this scanner's delimiting pattern to a pattern constructed from the specified String.
public  ScanneruseLocale(Locale locale)
     Sets this scanner's locale to the specified locale.
public  ScanneruseRadix(int radix)
     Sets this scanner's default radix to the specified radix.


Constructor Detail
Scanner
public Scanner(Readable source)(Code)
Constructs a new Scanner that produces values scanned from the specified source.
Parameters:
  source - A character source implementing the Readableinterface



Scanner
public Scanner(InputStream source)(Code)
Constructs a new Scanner that produces values scanned from the specified input stream. Bytes from the stream are converted into characters using the underlying platform's .
Parameters:
  source - An input stream to be scanned



Scanner
public Scanner(InputStream source, String charsetName)(Code)
Constructs a new Scanner that produces values scanned from the specified input stream. Bytes from the stream are converted into characters using the specified charset.
Parameters:
  source - An input stream to be scanned
Parameters:
  charsetName - The encoding type used to convert bytes from thestream into characters to be scanned
throws:
  IllegalArgumentException - if the specified character setdoes not exist



Scanner
public Scanner(File source) throws FileNotFoundException(Code)
Constructs a new Scanner that produces values scanned from the specified file. Bytes from the file are converted into characters using the underlying platform's .
Parameters:
  source - A file to be scanned
throws:
  FileNotFoundException - if source is not found



Scanner
public Scanner(File source, String charsetName) throws FileNotFoundException(Code)
Constructs a new Scanner that produces values scanned from the specified file. Bytes from the file are converted into characters using the specified charset.
Parameters:
  source - A file to be scanned
Parameters:
  charsetName - The encoding type used to convert bytes from the fileinto characters to be scanned
throws:
  FileNotFoundException - if source is not found
throws:
  IllegalArgumentException - if the specified encoding is not found



Scanner
public Scanner(String source)(Code)
Constructs a new Scanner that produces values scanned from the specified string.
Parameters:
  source - A string to scan



Scanner
public Scanner(ReadableByteChannel source)(Code)
Constructs a new Scanner that produces values scanned from the specified channel. Bytes from the source are converted into characters using the underlying platform's .
Parameters:
  source - A channel to scan



Scanner
public Scanner(ReadableByteChannel source, String charsetName)(Code)
Constructs a new Scanner that produces values scanned from the specified channel. Bytes from the source are converted into characters using the specified charset.
Parameters:
  source - A channel to scan
Parameters:
  charsetName - The encoding type used to convert bytes from thechannel into characters to be scanned
throws:
  IllegalArgumentException - if the specified character setdoes not exist




Method Detail
close
public void close()(Code)
Closes this scanner.

If this scanner has not yet been closed then if its underlying also implements the java.io.Closeable interface then the readable's close method will be invoked. If this scanner is already closed then invoking this method will have no effect.

Attempting to perform search operations after a scanner has been closed will result in an IllegalStateException .




delimiter
public Pattern delimiter()(Code)
Returns the Pattern this Scanner is currently using to match delimiters. this scanner's delimiting pattern.



findInLine
public String findInLine(String pattern)(Code)
Attempts to find the next occurrence of a pattern constructed from the specified string, ignoring delimiters.

An invocation of this method of the form findInLine(pattern) behaves in exactly the same way as the invocation findInLine(Pattern.compile(pattern)).
Parameters:
  pattern - a string specifying the pattern to search for the text that matched the specified pattern
throws:
  IllegalStateException - if this scanner is closed




findInLine
public String findInLine(Pattern pattern)(Code)
Attempts to find the next occurrence of the specified pattern ignoring delimiters. If the pattern is found before the next line separator, the scanner advances past the input that matched and returns the string that matched the pattern. If no such pattern is detected in the input up to the next line separator, then null is returned and the scanner's position is unchanged. This method may block waiting for input that matches the pattern.

Since this method continues to search through the input looking for the specified pattern, it may buffer all of the input searching for the desired token if no line separators are present.
Parameters:
  pattern - the pattern to scan for the text that matched the specified pattern
throws:
  IllegalStateException - if this scanner is closed




findWithinHorizon
public String findWithinHorizon(String pattern, int horizon)(Code)
Attempts to find the next occurrence of a pattern constructed from the specified string, ignoring delimiters.

An invocation of this method of the form findWithinHorizon(pattern) behaves in exactly the same way as the invocation findWithinHorizon(Pattern.compile(pattern, horizon)).
Parameters:
  pattern - a string specifying the pattern to search for the text that matched the specified pattern
throws:
  IllegalStateException - if this scanner is closed
throws:
  IllegalArgumentException - if horizon is negative




findWithinHorizon
public String findWithinHorizon(Pattern pattern, int horizon)(Code)
Attempts to find the next occurrence of the specified pattern.

This method searches through the input up to the specified search horizon, ignoring delimiters. If the pattern is found the scanner advances past the input that matched and returns the string that matched the pattern. If no such pattern is detected then the null is returned and the scanner's position remains unchanged. This method may block waiting for input that matches the pattern.

A scanner will never search more than horizon code points beyond its current position. Note that a match may be clipped by the horizon; that is, an arbitrary match result may have been different if the horizon had been larger. The scanner treats the horizon as a transparent, non-anchoring bound (see Matcher.useTransparentBounds and Matcher.useAnchoringBounds ).

If horizon is 0, then the horizon is ignored and this method continues to search through the input looking for the specified pattern without bound. In this case it may buffer all of the input searching for the pattern.

If horizon is negative, then an IllegalArgumentException is thrown.
Parameters:
  pattern - the pattern to scan for the text that matched the specified pattern
throws:
  IllegalStateException - if this scanner is closed
throws:
  IllegalArgumentException - if horizon is negative




hasNext
public boolean hasNext()(Code)
Returns true if this scanner has another token in its input. This method may block while waiting for input to scan. The scanner does not advance past any input. true if and only if this scanner has another token
throws:
  IllegalStateException - if this scanner is closed
See Also:   java.util.Iterator



hasNext
public boolean hasNext(String pattern)(Code)
Returns true if the next token matches the pattern constructed from the specified string. The scanner does not advance past any input.

An invocation of this method of the form hasNext(pattern) behaves in exactly the same way as the invocation hasNext(Pattern.compile(pattern)).
Parameters:
  pattern - a string specifying the pattern to scan true if and only if this scanner has another token matchingthe specified pattern
throws:
  IllegalStateException - if this scanner is closed




hasNext
public boolean hasNext(Pattern pattern)(Code)
Returns true if the next complete token matches the specified pattern. A complete token is prefixed and postfixed by input that matches the delimiter pattern. This method may block while waiting for input. The scanner does not advance past any input.
Parameters:
  pattern - the pattern to scan for true if and only if this scanner has another token matchingthe specified pattern
throws:
  IllegalStateException - if this scanner is closed



hasNextBigDecimal
public boolean hasNextBigDecimal()(Code)
Returns true if the next token in this scanner's input can be interpreted as a BigDecimal using the Scanner.nextBigDecimal method. The scanner does not advance past any input. true if and only if this scanner's next token is a validBigDecimal
throws:
  IllegalStateException - if this scanner is closed



hasNextBigInteger
public boolean hasNextBigInteger()(Code)
Returns true if the next token in this scanner's input can be interpreted as a BigInteger in the default radix using the Scanner.nextBigInteger method. The scanner does not advance past any input. true if and only if this scanner's next token is a validBigInteger
throws:
  IllegalStateException - if this scanner is closed



hasNextBigInteger
public boolean hasNextBigInteger(int radix)(Code)
Returns true if the next token in this scanner's input can be interpreted as a BigInteger in the specified radix using the Scanner.nextBigInteger method. The scanner does not advance past any input.
Parameters:
  radix - the radix used to interpret the token as an integer true if and only if this scanner's next token is a validBigInteger
throws:
  IllegalStateException - if this scanner is closed



hasNextBoolean
public boolean hasNextBoolean()(Code)
Returns true if the next token in this scanner's input can be interpreted as a boolean value using a case insensitive pattern created from the string "true|false". The scanner does not advance past the input that matched. true if and only if this scanner's next token is a validboolean value
throws:
  IllegalStateException - if this scanner is closed



hasNextByte
public boolean hasNextByte()(Code)
Returns true if the next token in this scanner's input can be interpreted as a byte value in the default radix using the Scanner.nextByte method. The scanner does not advance past any input. true if and only if this scanner's next token is a validbyte value
throws:
  IllegalStateException - if this scanner is closed



hasNextByte
public boolean hasNextByte(int radix)(Code)
Returns true if the next token in this scanner's input can be interpreted as a byte value in the specified radix using the Scanner.nextByte method. The scanner does not advance past any input.
Parameters:
  radix - the radix used to interpret the token as a byte value true if and only if this scanner's next token is a validbyte value
throws:
  IllegalStateException - if this scanner is closed



hasNextDouble
public boolean hasNextDouble()(Code)
Returns true if the next token in this scanner's input can be interpreted as a double value using the Scanner.nextDouble method. The scanner does not advance past any input. true if and only if this scanner's next token is a validdouble value
throws:
  IllegalStateException - if this scanner is closed



hasNextFloat
public boolean hasNextFloat()(Code)
Returns true if the next token in this scanner's input can be interpreted as a float value using the Scanner.nextFloat method. The scanner does not advance past any input. true if and only if this scanner's next token is a validfloat value
throws:
  IllegalStateException - if this scanner is closed



hasNextInt
public boolean hasNextInt()(Code)
Returns true if the next token in this scanner's input can be interpreted as an int value in the default radix using the Scanner.nextInt method. The scanner does not advance past any input. true if and only if this scanner's next token is a validint value
throws:
  IllegalStateException - if this scanner is closed



hasNextInt
public boolean hasNextInt(int radix)(Code)
Returns true if the next token in this scanner's input can be interpreted as an int value in the specified radix using the Scanner.nextInt method. The scanner does not advance past any input.
Parameters:
  radix - the radix used to interpret the token as an int value true if and only if this scanner's next token is a validint value
throws:
  IllegalStateException - if this scanner is closed



hasNextLine
public boolean hasNextLine()(Code)
Returns true if there is another line in the input of this scanner. This method may block while waiting for input. The scanner does not advance past any input. true if and only if this scanner has another line of input
throws:
  IllegalStateException - if this scanner is closed



hasNextLong
public boolean hasNextLong()(Code)
Returns true if the next token in this scanner's input can be interpreted as a long value in the default radix using the Scanner.nextLong method. The scanner does not advance past any input. true if and only if this scanner's next token is a validlong value
throws:
  IllegalStateException - if this scanner is closed



hasNextLong
public boolean hasNextLong(int radix)(Code)
Returns true if the next token in this scanner's input can be interpreted as a long value in the specified radix using the Scanner.nextLong method. The scanner does not advance past any input.
Parameters:
  radix - the radix used to interpret the token as a long value true if and only if this scanner's next token is a validlong value
throws:
  IllegalStateException - if this scanner is closed



hasNextShort
public boolean hasNextShort()(Code)
Returns true if the next token in this scanner's input can be interpreted as a short value in the default radix using the Scanner.nextShort method. The scanner does not advance past any input. true if and only if this scanner's next token is a validshort value in the default radix
throws:
  IllegalStateException - if this scanner is closed



hasNextShort
public boolean hasNextShort(int radix)(Code)
Returns true if the next token in this scanner's input can be interpreted as a short value in the specified radix using the Scanner.nextShort method. The scanner does not advance past any input.
Parameters:
  radix - the radix used to interpret the token as a short value true if and only if this scanner's next token is a validshort value in the specified radix
throws:
  IllegalStateException - if this scanner is closed



ioException
public IOException ioException()(Code)
Returns the IOException last thrown by this Scanner's underlying Readable. This method returns null if no such exception exists. the last exception thrown by this scanner's readable



locale
public Locale locale()(Code)
Returns this scanner's locale.

A scanner's locale affects many elements of its default primitive matching regular expressions; see localized numbers above. this scanner's locale




match
public MatchResult match()(Code)
Returns the match result of the last scanning operation performed by this scanner. This method throws IllegalStateException if no match has been performed, or if the last match was not successful.

The various nextmethods of Scanner make a match result available if they complete without throwing an exception. For instance, after an invocation of the Scanner.nextInt method that returned an int, this method returns a MatchResult for the search of the Integer regular expression defined above. Similarly the Scanner.findInLine , Scanner.findWithinHorizon , and Scanner.skip methods will make a match available if they succeed. a match result for the last match operation
throws:
  IllegalStateException - If no match result is available




next
public String next()(Code)
Finds and returns the next complete token from this scanner. A complete token is preceded and followed by input that matches the delimiter pattern. This method may block while waiting for input to scan, even if a previous invocation of Scanner.hasNext returned true. the next token
throws:
  NoSuchElementException - if no more tokens are available
throws:
  IllegalStateException - if this scanner is closed
See Also:   java.util.Iterator



next
public String next(String pattern)(Code)
Returns the next token if it matches the pattern constructed from the specified string. If the match is successful, the scanner advances past the input that matched the pattern.

An invocation of this method of the form next(pattern) behaves in exactly the same way as the invocation next(Pattern.compile(pattern)).
Parameters:
  pattern - a string specifying the pattern to scan the next token
throws:
  NoSuchElementException - if no such tokens are available
throws:
  IllegalStateException - if this scanner is closed




next
public String next(Pattern pattern)(Code)
Returns the next token if it matches the specified pattern. This method may block while waiting for input to scan, even if a previous invocation of Scanner.hasNext(Pattern) returned true. If the match is successful, the scanner advances past the input that matched the pattern.
Parameters:
  pattern - the pattern to scan for the next token
throws:
  NoSuchElementException - if no more tokens are available
throws:
  IllegalStateException - if this scanner is closed



nextBigDecimal
public BigDecimal nextBigDecimal()(Code)
Scans the next token of the input as a java.math.BigDecimalBigDecimal .

If the next token matches the Decimal regular expression defined above then the token is converted into a BigDecimal value as if by removing all group separators, mapping non-ASCII digits into ASCII digits via the Character.digit Character.digit , and passing the resulting string to the java.math.BigDecimal.BigDecimal(java.lang.String) BigDecimal(String) constructor. the BigDecimal scanned from the input
throws:
  InputMismatchException - if the next token does not match the Decimalregular expression, or is out of range
throws:
  NoSuchElementException - if the input is exhausted
throws:
  IllegalStateException - if this scanner is closed




nextBigInteger
public BigInteger nextBigInteger()(Code)
Scans the next token of the input as a java.math.BigIntegerBigInteger .

An invocation of this method of the form nextBigInteger() behaves in exactly the same way as the invocation nextBigInteger(radix), where radix is the default radix of this scanner. the BigInteger scanned from the input
throws:
  InputMismatchException - if the next token does not match the Integerregular expression, or is out of range
throws:
  NoSuchElementException - if the input is exhausted
throws:
  IllegalStateException - if this scanner is closed




nextBigInteger
public BigInteger nextBigInteger(int radix)(Code)
Scans the next token of the input as a java.math.BigIntegerBigInteger .

If the next token matches the Integer regular expression defined above then the token is converted into a BigInteger value as if by removing all group separators, mapping non-ASCII digits into ASCII digits via the Character.digit Character.digit , and passing the resulting string to the java.math.BigInteger.BigInteger(java.lang.String) BigInteger(String, int) constructor with the specified radix.
Parameters:
  radix - the radix used to interpret the token the BigInteger scanned from the input
throws:
  InputMismatchException - if the next token does not match the Integerregular expression, or is out of range
throws:
  NoSuchElementException - if the input is exhausted
throws:
  IllegalStateException - if this scanner is closed




nextBoolean
public boolean nextBoolean()(Code)
Scans the next token of the input into a boolean value and returns that value. This method will throw InputMismatchException if the next token cannot be translated into a valid boolean value. If the match is successful, the scanner advances past the input that matched. the boolean scanned from the input
throws:
  InputMismatchException - if the next token is not a valid boolean
throws:
  NoSuchElementException - if input is exhausted
throws:
  IllegalStateException - if this scanner is closed



nextByte
public byte nextByte()(Code)
Scans the next token of the input as a byte.

An invocation of this method of the form nextByte() behaves in exactly the same way as the invocation nextByte(radix), where radix is the default radix of this scanner. the byte scanned from the input
throws:
  InputMismatchException - if the next token does not match the Integerregular expression, or is out of range
throws:
  NoSuchElementException - if input is exhausted
throws:
  IllegalStateException - if this scanner is closed




nextByte
public byte nextByte(int radix)(Code)
Scans the next token of the input as a byte. This method will throw InputMismatchException if the next token cannot be translated into a valid byte value as described below. If the translation is successful, the scanner advances past the input that matched.

If the next token matches the Integer regular expression defined above then the token is converted into a byte value as if by removing all locale specific prefixes, group separators, and locale specific suffixes, then mapping non-ASCII digits into ASCII digits via Character.digit Character.digit , prepending a negative sign (-) if the locale specific negative prefixes and suffixes were present, and passing the resulting string to Byte.parseByte(Stringint) Byte.parseByte with the specified radix.
Parameters:
  radix - the radix used to interpret the token as a byte value the byte scanned from the input
throws:
  InputMismatchException - if the next token does not match the Integerregular expression, or is out of range
throws:
  NoSuchElementException - if input is exhausted
throws:
  IllegalStateException - if this scanner is closed




nextDouble
public double nextDouble()(Code)
Scans the next token of the input as a double. This method will throw InputMismatchException if the next token cannot be translated into a valid double value. If the translation is successful, the scanner advances past the input that matched.

If the next token matches the Float regular expression defined above then the token is converted into a double value as if by removing all locale specific prefixes, group separators, and locale specific suffixes, then mapping non-ASCII digits into ASCII digits via Character.digit Character.digit , prepending a negative sign (-) if the locale specific negative prefixes and suffixes were present, and passing the resulting string to Double.parseDouble Double.parseDouble . If the token matches the localized NaN or infinity strings, then either "Nan" or "Infinity" is passed to Double.parseDouble(String) Double.parseDouble as appropriate. the double scanned from the input
throws:
  InputMismatchException - if the next token does not match the Floatregular expression, or is out of range
throws:
  NoSuchElementException - if the input is exhausted
throws:
  IllegalStateException - if this scanner is closed




nextFloat
public float nextFloat()(Code)
Scans the next token of the input as a float. This method will throw InputMismatchException if the next token cannot be translated into a valid float value as described below. If the translation is successful, the scanner advances past the input that matched.

If the next token matches the Float regular expression defined above then the token is converted into a float value as if by removing all locale specific prefixes, group separators, and locale specific suffixes, then mapping non-ASCII digits into ASCII digits via Character.digit Character.digit , prepending a negative sign (-) if the locale specific negative prefixes and suffixes were present, and passing the resulting string to Float.parseFloat Float.parseFloat . If the token matches the localized NaN or infinity strings, then either "Nan" or "Infinity" is passed to Float.parseFloat(String) Float.parseFloat as appropriate. the float scanned from the input
throws:
  InputMismatchException - if the next token does not match the Floatregular expression, or is out of range
throws:
  NoSuchElementException - if input is exhausted
throws:
  IllegalStateException - if this scanner is closed




nextInt
public int nextInt()(Code)
Scans the next token of the input as an int.

An invocation of this method of the form nextInt() behaves in exactly the same way as the invocation nextInt(radix), where radix is the default radix of this scanner. the int scanned from the input
throws:
  InputMismatchException - if the next token does not match the Integerregular expression, or is out of range
throws:
  NoSuchElementException - if input is exhausted
throws:
  IllegalStateException - if this scanner is closed




nextInt
public int nextInt(int radix)(Code)
Scans the next token of the input as an int. This method will throw InputMismatchException if the next token cannot be translated into a valid int value as described below. If the translation is successful, the scanner advances past the input that matched.

If the next token matches the Integer regular expression defined above then the token is converted into an int value as if by removing all locale specific prefixes, group separators, and locale specific suffixes, then mapping non-ASCII digits into ASCII digits via Character.digit Character.digit , prepending a negative sign (-) if the locale specific negative prefixes and suffixes were present, and passing the resulting string to Integer.parseInt(Stringint) Integer.parseInt with the specified radix.
Parameters:
  radix - the radix used to interpret the token as an int value the int scanned from the input
throws:
  InputMismatchException - if the next token does not match the Integerregular expression, or is out of range
throws:
  NoSuchElementException - if input is exhausted
throws:
  IllegalStateException - if this scanner is closed




nextLine
public String nextLine()(Code)
Advances this scanner past the current line and returns the input that was skipped. This method returns the rest of the current line, excluding any line separator at the end. The position is set to the beginning of the next line.

Since this method continues to search through the input looking for a line separator, it may buffer all of the input searching for the line to skip if no line separators are present. the line that was skipped
throws:
  NoSuchElementException - if no line was found
throws:
  IllegalStateException - if this scanner is closed




nextLong
public long nextLong()(Code)
Scans the next token of the input as a long.

An invocation of this method of the form nextLong() behaves in exactly the same way as the invocation nextLong(radix), where radix is the default radix of this scanner. the long scanned from the input
throws:
  InputMismatchException - if the next token does not match the Integerregular expression, or is out of range
throws:
  NoSuchElementException - if input is exhausted
throws:
  IllegalStateException - if this scanner is closed




nextLong
public long nextLong(int radix)(Code)
Scans the next token of the input as a long. This method will throw InputMismatchException if the next token cannot be translated into a valid long value as described below. If the translation is successful, the scanner advances past the input that matched.

If the next token matches the Integer regular expression defined above then the token is converted into a long value as if by removing all locale specific prefixes, group separators, and locale specific suffixes, then mapping non-ASCII digits into ASCII digits via Character.digit Character.digit , prepending a negative sign (-) if the locale specific negative prefixes and suffixes were present, and passing the resulting string to Long.parseLong(Stringint) Long.parseLong with the specified radix.
Parameters:
  radix - the radix used to interpret the token as an int value the long scanned from the input
throws:
  InputMismatchException - if the next token does not match the Integerregular expression, or is out of range
throws:
  NoSuchElementException - if input is exhausted
throws:
  IllegalStateException - if this scanner is closed




nextShort
public short nextShort()(Code)
Scans the next token of the input as a short.

An invocation of this method of the form nextShort() behaves in exactly the same way as the invocation nextShort(radix), where radix is the default radix of this scanner. the short scanned from the input
throws:
  InputMismatchException - if the next token does not match the Integerregular expression, or is out of range
throws:
  NoSuchElementException - if input is exhausted
throws:
  IllegalStateException - if this scanner is closed




nextShort
public short nextShort(int radix)(Code)
Scans the next token of the input as a short. This method will throw InputMismatchException if the next token cannot be translated into a valid short value as described below. If the translation is successful, the scanner advances past the input that matched.

If the next token matches the Integer regular expression defined above then the token is converted into a short value as if by removing all locale specific prefixes, group separators, and locale specific suffixes, then mapping non-ASCII digits into ASCII digits via Character.digit Character.digit , prepending a negative sign (-) if the locale specific negative prefixes and suffixes were present, and passing the resulting string to Short.parseShort(Stringint) Short.parseShort with the specified radix.
Parameters:
  radix - the radix used to interpret the token as a short value the short scanned from the input
throws:
  InputMismatchException - if the next token does not match the Integerregular expression, or is out of range
throws:
  NoSuchElementException - if input is exhausted
throws:
  IllegalStateException - if this scanner is closed




radix
public int radix()(Code)
Returns this scanner's default radix.

A scanner's radix affects elements of its default number matching regular expressions; see localized numbers above. the default radix of this scanner




remove
public void remove()(Code)
The remove operation is not supported by this implementation of Iterator.
throws:
  UnsupportedOperationException - if this method is invoked.
See Also:   java.util.Iterator



reset
public Scanner reset()(Code)
Resets this scanner.

Resetting a scanner discards all of its explicit state information which may have been changed by invocations of Scanner.useDelimiter , Scanner.useLocale , or Scanner.useRadix .

An invocation of this method of the form scanner.reset() behaves in exactly the same way as the invocation

 scanner.useDelimiter("\\p{javaWhitespace}+")
 .useLocale(Locale.getDefault())
 .useRadix(10);
 
this scanner
since:
   1.6



skip
public Scanner skip(Pattern pattern)(Code)
Skips input that matches the specified pattern, ignoring delimiters. This method will skip input if an anchored match of the specified pattern succeeds.

If a match to the specified pattern is not found at the current position, then no input is skipped and a NoSuchElementException is thrown.

Since this method seeks to match the specified pattern starting at the scanner's current position, patterns that can match a lot of input (".*", for example) may cause the scanner to buffer a large amount of input.

Note that it is possible to skip something without risking a NoSuchElementException by using a pattern that can match nothing, e.g., sc.skip("[ \t]*").
Parameters:
  pattern - a string specifying the pattern to skip over this scanner
throws:
  NoSuchElementException - if the specified pattern is not found
throws:
  IllegalStateException - if this scanner is closed




skip
public Scanner skip(String pattern)(Code)
Skips input that matches a pattern constructed from the specified string.

An invocation of this method of the form skip(pattern) behaves in exactly the same way as the invocation skip(Pattern.compile(pattern)).
Parameters:
  pattern - a string specifying the pattern to skip over this scanner
throws:
  IllegalStateException - if this scanner is closed




toString
public String toString()(Code)

Returns the string representation of this Scanner. The string representation of a Scanner contains information that may be useful for debugging. The exact format is unspecified. The string representation of this scanner




useDelimiter
public Scanner useDelimiter(Pattern pattern)(Code)
Sets this scanner's delimiting pattern to the specified pattern.
Parameters:
  pattern - A delimiting pattern this scanner



useDelimiter
public Scanner useDelimiter(String pattern)(Code)
Sets this scanner's delimiting pattern to a pattern constructed from the specified String.

An invocation of this method of the form useDelimiter(pattern) behaves in exactly the same way as the invocation useDelimiter(Pattern.compile(pattern)).

Invoking the Scanner.reset method will set the scanner's delimiter to the default.
Parameters:
  pattern - A string specifying a delimiting pattern this scanner




useLocale
public Scanner useLocale(Locale locale)(Code)
Sets this scanner's locale to the specified locale.

A scanner's locale affects many elements of its default primitive matching regular expressions; see localized numbers above.

Invoking the Scanner.reset method will set the scanner's locale to the initial locale.
Parameters:
  locale - A string specifying the locale to use this scanner




useRadix
public Scanner useRadix(int radix)(Code)
Sets this scanner's default radix to the specified radix.

A scanner's radix affects elements of its default number matching regular expressions; see localized numbers above.

If the radix is less than Character.MIN_RADIX or greater than Character.MAX_RADIX, then an IllegalArgumentException is thrown.

Invoking the Scanner.reset method will set the scanner's radix to 10.
Parameters:
  radix - The radix to use when scanning numbers this scanner
throws:
  IllegalArgumentException - if radix is out of range




Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.