π™‹π™–π™§π™¨π™žπ™£π™œ : JAVA CSV 파일 νŒŒμ‹±

uuuouuoΒ·2022λ…„ 4μ›” 29일
0
post-thumbnail

πŸ“ CSV Parsing


β–ͺ code

BufferedReader file = new BufferedReader(
        new FileReader("csv 파일 μœ„μΉ˜\\csv 파일 이름"));
    String line = "";

    try {
      Set<String> set = new HashSet<>();
      while ((line = file.readLine()) != null) { // readLine()은 νŒŒμΌμ—μ„œ κ°œν–‰λœ ν•œ μ€„μ˜ 데이터λ₯Ό μ½μ–΄μ˜¨λ‹€.
        List<String> aLine = new ArrayList<>();
        String[] arr = line.split(","); // 파일의 ν•œ 쀄을 ,둜 λ‚˜λˆ„μ–΄ 배열에 μ €μž₯ ν›„ 리슀트둜 λ³€ν™˜ν•œλ‹€.

        for (String s : arr) {
          System.out.println(s);
        }

      }

    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      try {
        if (file != null) {
          file.close();
        }
      } catch (IOException e) {
        e.printStackTrace();
      }
    }

0개의 λŒ“κΈ€