你好,我有这段代码:
Scanner input = new Scanner(new File("src/data/input.csv"));
input.useDelimiter(",|\\n");
System.out.println(input.next());
System.out.println(input.next());
System.out.println(input.next());
System.out.println(input.next());
System.out.println(input.next());
System.out.println(input.next());
System.out.println(input.next());
System.out.println(input.next());
System.out.println(input.next());
System.out.println(input.next());
Input.csv是:
-149.95038,61.13712,"麦当劳-安克雷奇,AK","3828 W Dimond Blvd,Anchorage,AK,(907) 248-0597"
-149.93538,61.18167,"麦当劳-安克雷奇,AK","4350 Spenard Rd,Anchorage,AK (907) 243-5122"
我期望的输出结果是:
-149.95038
61.13712
"麦当劳-安克雷奇
AK"
"3828 W Dimond Blvd
Anchorage
AK
(907) 248-0597"
-149.93538
61.18167
但我得到的结果是:
-149.95038
61.13712
"麦当劳-安克雷奇
AK"
"3828 W Dimond Blvd
Anchorage
AK
(907) 248-0597"
(空行)
-149.93538
61.18167
我不确定为什么换行符没有被跳过。有没有更好的方法从输入文件中获取值?