Scanner in = new Scanner(Path.of("C:\\Users\\Administrator\\Desktop\\hello.txt"), StandardCharsets.UTF_8);
时间: 2023-08-27 10:20:34 浏览: 74
这段代码使用了Scanner类和Path类来实现从文件中读取字符串。Scanner的构造函数接受一个Path对象和字符集参数,以便读取指定路径下的文件并使用指定的字符集编码。具体来说,代码中的Scanner对象使用了Path.of()方法来创建一个Path对象,然后传入Scanner的构造函数中,同时指定了字符集为UTF-8。这样,Scanner就可以从指定路径下的hello.txt文件中按照UTF-8编码读取字符串了。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [Java自学笔记06(IO流)](https://blog.csdn.net/ZZBvos/article/details/124245325)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [25.java中IO流的应用---缓冲流、转换流以及对象流过程(附讲解和练习)](https://blog.csdn.net/Royalic/article/details/119332286)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文