[Java] CSV파일 파싱하기<수정중>

ii_ruatnec·2023년 8월 9일

Java

목록 보기
1/1
post-thumbnail
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class csv_parsing {
    public static void main(String[] args) {
        List<List<String>> ret = new ArrayList<List<String>>();
        BufferedReader br = null;

        try {
            br = Files.newBufferedReader(Paths.get("C:\\.csv"));
            String line = "";

            while ((line = br.readLine()) != null) {
                List<String> tmpList = new ArrayList<String>();
                String array[] = line.split(",");
                tmpList = Arrays.asList(array);
                System.out.println(tmpList);
                ret.add(tmpList);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (br != null) {
                    br.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
profile
세상의 변화에 흥미를 느끼는 개발자

1개의 댓글

comment-user-thumbnail
2023년 8월 9일

정리가 잘 된 글이네요. 도움이 됐습니다.

답글 달기