正则表达式:
然后查看源码知道useDelimiter 下面的实现使用的是Pattern,参考文章得知:
https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html
Boundary matchers
^ The beginning of a line
$ The end of a line
\b A word boundary
\B A non-word boundary
\A The beginning of the input
\G The end of the previous match
\Z The end of the input but for the final terminator, if any
\z The end of the input
正则表达式"\\A"跟"^"的作用是一样的,代表文本的开头。
\A是从字符串开头进行匹配,\Z是从字符串结尾进行匹配。这两个是不考虑行的。^是从行首,$是从行尾。
这里表示:以文本的开头作为分隔符分割文本。
如此这般,就能一下子获取整段文本的内容了,同时Scanner也在内部完成了InputStream转String的操作。
优点:节省书写代码,即不需要我们再写循环把inputStream的内容读到byte[]再放进String。
import java.util.Scanner;
import java.io.File ;
import java.io.InputStream ;
import java.io.FileInputStream ;
imp

本文介绍了Java中正则表达式的边界匹配器,如^, $, , B, A, G, , z,并展示了如何使用Scanner的useDelimiter方法以文本开头作为分隔符。此外,还详细讲解了Java获取resource目录下文件路径的不同方法,包括Class.getResource(), ClassLoader.getResource(), ClassLoader.getSystemResource()以及Thread.currentThread().getContextClassLoader().getResource()的使用和规律。"
115479588,9846721,Java实现AES-128 BASE64加密:16位与32位密钥,"['java', '加密', 'AES', '密钥管理']
最低0.47元/天 解锁文章
15万+

被折叠的 条评论
为什么被折叠?



