Ask and Learn


使用 python 后,觉得读写文件非常方便,偶尔用到 java IO 时就开始头疼,想要一次性从输入流中读取全部内容,还挺费事。

折腾了一阵,终于找到了解决方法: java.util.Scanner

public Scanner useDelimiter(String pattern) Sets this scanner’s delimiting pattern to a pattern constructed from the specified String. An invocation of this method of the form useDelimiter(pattern) behaves in exactly the same way as the invocation hasDelimiter(Pattern.compile(pattern)).

pattern - A string specifying a delimiting pattern
Returns: this scanner

如果将 delimeter 设置为文末,不就一次性取得所有的内容了。

URL url = new URL("");
Scanner sc = new Scanner(url.openStream());
sc = sc.useDelimiter("$");
String content =;