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

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

**关闭。**此题需要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的行和列

  1. while(done == false){
  2. reader2 = new BufferedReader(new FileReader(file));
  3. System.out.println("State a champ name:");
  4. String name = sc.nextLine();
  5. while((ln = reader2.readLine()) != null){
  6. String[] values = ln.split(",");
  7. System.out.println(values[0]);
  8. if(values[0] == name){
  9. for(int i = 0; i < arr2.length; i++){
  10. arr2[i] = values[counter];
  11. System.out.println("aa");
  12. counter++;
  13. }

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

u0njafvf

u0njafvf1#

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

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

相关问题