读取单行文本文件,拆分为数组

use*_*293 7 java arrays text split file

我正在从一个看起来完全像这样的文本文件中读取一长串信息:

Sebastien 5000\\Loic 5000\\Shubhashisshh 5000\\Thibaullt 5000\\Caroo 5000\\Blabla 5000\\Okayyy 5000\\SebCed 5000\\abusee 5000\\omg 5000\\

它应该是用户名称的高分.当我打印出该行时,它看起来应该是这样,但是当我在使用后打印出数组时split("\\\\"),它看起来像这样:

[Sebastien 5000, , Loic 5000, , Shubhashisshh 5000, , Thibaullt 5000, , Caroo 5000, , Blabla 5000, , Okayyy 5000, , SebCed 5000, , abusee 5000, , omg 5000]

问题是,Array[0]是好的,但是Array[1]是空的,因为都是Array[3],Array[5]等等.

这是我的代码.它出什么问题了?

            BufferedReader in = null;
    try {
        in = new BufferedReader(new FileReader(path));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }

    String line = null;
    try {
        line = in.readLine();
    } catch (IOException e) {
        e.printStackTrace();
    }
    System.out.println("LINE = "+line);

    String[] scores = line.split("\\\\");

    System.out.println("Mode = "+mode+Arrays.toString(scores));
Run Code Online (Sandbox Code Playgroud)

Jos*_*ior 9

那是因为"\\\\"正在被解析为\\,并且split方法使用正则表达式,因此\\正在变为\,然后Sebastien 5000\\Loic 5000将导致[Sebastien 5000,,Loic 5000]

改为: "\\\\\\\\"