如何读取CSV文件的确切行和列[已关闭]

u3r8eeie  于 2023-06-03  发布在  其他
关注(0)|答案(1)|浏览(411)

**关闭。**此题需要debugging details。目前不接受答复。

编辑问题以包括desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem。这将帮助其他人回答这个问题。
昨天关门了。
Improve this question
我尝试从csv文件中读取,并尝试访问csv文件的特定行和列。如何获取csv文件enter image description here的行和列

while(done == false){
            reader2 = new BufferedReader(new FileReader(file));
            System.out.println("State a champ name:");
            String name = sc.nextLine();
            while((ln = reader2.readLine()) != null){
                String[] values = ln.split(",");
                System.out.println(values[0]);
                if(values[0] == name){
                    for(int i = 0; i < arr2.length; i++){
                        arr2[i] = values[counter];
                        System.out.println("aa");
                        counter++;
                    }

我试着把它做成一个2d数组,并尝试了其他的东西,但没有工作。

u0njafvf

u0njafvf1#

可以使用以下方法获取特定行和列的值。

String get(String path, int row, int column) throws IOException {
    try (BufferedReader reader = new BufferedReader(new FileReader(path))) {
        String line;
        int count = 0;
        while ((line = reader.readLine()) != null) {
            if (count++ == row) return line.split(",", -1)[column];
        }
    }
    return null;
}

相关问题