useDelimiter不会识别竖条,但会识别其他字符.
这不起作用:
scan.useDelimiter("|");
Run Code Online (Sandbox Code Playgroud)
这确实有效:
scan.useDelimiter(",");
Run Code Online (Sandbox Code Playgroud)
其余代码:
Scanner scan = new Scanner("12,d, |, f | ");
// initialize the string delimiter
scan.useDelimiter(",");
// Printing the delimiter used
System.out.println("The delimiter use is "+scan.delimiter());
// Printing the tokenized Strings
while(scan.hasNext()){
System.out.print(scan.next());
}
// closing the scanner stream
scan.close();
Run Code Online (Sandbox Code Playgroud)