java scanner pattern_java scanner语句

展开全部

代码如下:/**

* Constructs a new {@code Scanner} that produces values scanned

* from the specified input stream. Bytes from the stream are converted

* into characters using the underlying platform's

* {@linkplain java.nio.charset.Charset#defaultCharset() default charset}.

*

* @param  source An input stream to be scanned

*/

public Scanner(InputStream source) {

this(new InputStreamReader(source), WHITESPACE_PATTERN);

}

在这个构造器中,只有一个参e68a843231313335323631343130323136353331333431346435数source,指的是需要被扫描的输入流。System.in是一个本地(native)的final常量,是可供用户输入的标准输入流。如果你这么写:try (Scanner sc = new Scanner(new FileInputStream(new File("D:\\5.txt"))))

{

while (sc.hasNextLine())

System.out.println(sc.nextLine());

}

catch (FileNotFoundException e)

{

e.printStackTrace();

}

就把Scanner的输入源重定位到了D盘下的5.txt文件,然后就可以按行读取文件了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值