简体   繁体   English

使用扫描仪读取文件

[英]using Scanner to read a file

I found the following useful in the past for reading in text files: 我发现以下对于阅读文本文件有用:

new Scanner(file).useDelimiter("\\Z").next();

However I came across a file today that was only partially read in with this syntax. 但是我今天遇到的文件只是用这种语法部分读入。 I'm not sure what makes this file special, it's just a .jsp 我不确定是什么让这个文件变得特别,它只是一个.jsp

I found the below worked in this instance but I'd like to know why the previous method didn't work. 我发现以下工作在这个实例中,但我想知道为什么以前的方法不起作用。

Scanner in = new Scanner(new FileReader(file));
String text = in.useDelimiter("\\Z").next();

Save the jsp file as .txt and try to read it using your first method. 将jsp文件保存为.txt并尝试使用第一种方法读取它。 if it works i feel size can be the issue. 如果它的工作,我觉得大小可能是问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM