Java中Scanner的使用

Constructor Summary(摘要)
Constructor and Description(构造函数和说明)                                                  charsetName为指定编码方式
Scanner(File source)            扫描仪 (文件源) 构造一个新扫描仪, 它生成从指定文件扫描的值。
Scanner(FileRef source)            扫描仪 (FileRef 源) 构造一个新的扫描仪, 它生成从指定文件扫描的值。
Scanner(FileRef source, String charsetName)            构造一个新的扫描程序, 该扫描仪生成从指定文件扫描的值。
Scanner(File source, String charsetName)            构造一个新的扫描程序, 该扫描仪生成从指定文件扫描的值。
Scanner(InputStream source)            构造一个新的扫描程序, 该扫描仪生成从指定的输入流中扫描的值。
Scanner(InputStream source, String charsetName)         构造一个新的扫描程序, 该扫描仪生成从指定的输入流中扫描的值。
Scanner(Readable source)            构造一个新的扫描程序, 该扫描仪生成从指定源扫描的值
Scanner(ReadableByteChannel source)            构造一个新的扫描程序, 该扫描仪生成从指定通道扫描的值。
Scanner(ReadableByteChannel source, String charsetName)     构造一个新的扫描程序, 该扫描仪生成从指定通道扫描的值。
Scanner(String source)           构造一个新的扫描程序, 该扫描仪生成从指定字符串扫描的值。


Method Summary(摘要)
Modifier修饰符 and Type  Method and Description pattern 模式类      delimiter 分隔符 radix 基数(指定进制)
 voidclose()           关闭此扫描仪。
 Patterndelimiter()           返回此扫描仪当前用于匹配模式串的分隔符。
 StringfindInLine(Pattern pattern)             尝试查找匹配指定模式的下一项, 忽略分隔符。
 StringfindInLine(String pattern)            尝试查找匹配指定字符串模式的下一项, 忽略分隔符。
 StringfindWithinHorizon(Pattern pattern, int horizon)           尝试查找匹配指定模式的下一项。
 StringfindWithinHorizon(String pattern, int horizon)           尝试查找从指定字符串构造的模式的下一个匹配项, 忽略分隔符。
 booleanhasNext()           如果此扫描仪的输入中有下一个标记, 则返回 true。
 booleanhasNext(Pattern pattern)            如果存在下一个标记与指定的模式匹配, 则返回 true。
 booleanhasNext(String pattern)            如果下一个标记与从指定字符串构造的模式匹配, 则返回 true。
 booleanhasNextBigDecimal()            如果此扫描仪输入中的下一个标记可以使用 nextBigDecimal () 方法解释为 BigDecimal, 则返回 true。
 booleanhasNextBigInteger()         如果此扫描仪输入中的下一个标记可以被解释为使用 nextBigInteger () 方法的默认基数中的 BigInteger, 则返回 true。
 booleanhasNextBigInteger(int radix)         如果此扫描仪输入中的下一个标记可以使用 nextBigInteger () 方法将其解释为指定基数中的 BigInteger, 则返回 true。  
 booleanhasNextBoolean()            如果此扫描仪输入中的下一个标记可以使用"true | false" 创建解释为布尔值, 则返回 true。
 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 nextByte() method.
 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 nextByte() method.
 booleanhasNextDouble()           Returns true if the next token in this scanner's input can be interpreted as a double value using the nextDouble() method.
 booleanhasNextFloat()           Returns true if the next token in this scanner's input can be interpreted as a float value using the nextFloat() method.
 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 nextInt() method.
 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 nextInt() method.
 booleanhasNextLine()           Returns true if there is another line in the input of this scanner.
 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 nextLong() method.
 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 nextLong() method.
 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 nextShort() method.
 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 nextShort() method.
 IOExceptionioException()           Returns the IOException last thrown by this Scanner's underlying Readable.
 Localelocale()            返回现在所处的下标
 MatchResultmatch()            返回此扫描仪上次执行扫描操作所匹配的结果。
 Stringnext()            返回此扫描仪的下一个标记。
 Stringnext(Pattern pattern)            如果匹配到指定模式中符合设定模式的, 则返回下一个标记。
 Stringnext(String pattern)            如果匹配到指定字符串中符合设定模式的, 则返回下一个标记。
 BigDecimalnextBigDecimal()           将输入的下一个标记作为BigDecimal类型扫描。
 BigIntegernextBigInteger()           将输入的下一个标记作为BigInteger类型扫描。
 BigIntegernextBigInteger(int radix)           将输入的下一个标记作为BigInteger类型扫描。
 booleannextBoolean()            将输入的下一个标记作为bool类型扫描。
 bytenextByte()            将输入的下一个标记作为字节扫描。
 bytenextByte(int radix)          将输入的下一个标记作为字节扫描。
 doublenextDouble()           将输入的下一个标记作为双精度扫描。
 floatnextFloat()           将输入的下一个标记作为双精度扫描。
 intnextInt()            将输入的下一个标记作为整数扫描。
 intnextInt(int radix)            将输入的下一个标记作为整数扫描。
 StringnextLine()            将此扫描仪向前推进, 并返回已跳过的字符。
 longnextLong()            将输入的下一个标记作为长整数扫描。
 longnextLong(int radix)            将输入的下一个标记作为长整数扫描。
 shortnextShort()            将输入的下一个标记作为短整数扫描。
 shortnextShort(int radix)            输入的下一个标记作为短整数扫描。
 intradix()            返回此扫描仪的默认基数。
 voidremove()            迭代器的实现不支持移除操作。
 Scannerreset()            重启扫描仪
 Scannerskip(Pattern pattern)            跳过与指定模式匹配的输入, 忽略分隔符。
 Scannerskip(String pattern)            跳过与指定字符串匹配的输入
 StringtoString()            返回此扫描仪的字符串表示形式
 ScanneruseDelimiter(Pattern pattern)            将此扫描仪的分隔模式设置为指定的模式。
 ScanneruseDelimiter(String pattern)            将此扫描仪分隔设置为指定字符串。
 ScanneruseLocale(Locale locale)            将此扫描仪当前下标设置设为指定的下标
 ScanneruseRadix(int radix)            将此扫描仪的默认基数设置为指定基数。


含有 radix的为指定进制,含有pattern的为模式串 ,使用delimiter为指定分隔符 ,locate为指定下标。

方法nextByte()、nextShort()、nextInt()、nextLong()、nextFloat()、nextDouble()、next()等都称为标记读取方法(token-reading method),因为它们会读取用分隔符分隔开的标记。默认情况下,分隔符是空格。

方法next()和nextLine()都会读取一个字符串。next()方法读取一个由分隔符分隔的字符串,但是nextLine()读取一个以换行符结束的行。

标记读取方法不能读取标记后面的分隔符。

如果在标记读取方法之后调用nextLIne(),该方法读取从这个分隔符开始,到这行的行分隔符结束的字符。这个行分隔符也被读取,但是它不是nextLIne()返回的字符串部分。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值