Java Scanner newline recognition

前端 未结 2 1894
我在风中等你
我在风中等你 2020-12-17 06:51

I can\'t find the documentation that specifies how a Scanner treats newline patterns by default. I want to read a file line by line and have the scanner be able to handle \\

2条回答
  •  抹茶落季
    2020-12-17 07:23

    Looking at the source code for Sun JDK 1.6, the pattern used is "\r\n|[\n\r\u2028\u2029\u0085]"

    which says "\r\n" or any one of \r, \n or the unicode characters for "line separator", "paragraph separator", and "next line" respectively.

提交回复
热议问题