시작하기무료로 시작하기

서식 있는 CSV 파일 쓰기

데이터를 정제한 후에는 다양한 사용자를 위해 내보내야 해요. 분석 팀은 표준 CSV를 원하고, 유럽권 시스템은 세미콜론 구분자를 기대하며, 레거시 메인프레임은 헤더가 없는 파일을 요구해요. 유연한 내보내기 옵션을 사용하면 여러 기술 환경에서 데이터를 원활하게 통합할 수 있어요.

TableCsvWriteOptions 클래스는 이미 가져와 두었어요.

이 연습은 강의의 일부입니다

Java에서 데이터 가져오기

강의 보기

연습 안내

  • 표준 CSV로 테이블을 작성하세요.
  • 세미콜론 구분자로 작성하세요.
  • 레거시 시스템을 위해 헤더 없이 작성하세요.

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

public class WriteCSVFiles {
    public static void main(String[] args) {
        try {
            Table employeePerformance = Table.read().csv("employee_performance.csv");
            System.out.println("Original data structure:");
            System.out.println(employeePerformance.structure());
            System.out.println("First 3 rows:");
            System.out.println(employeePerformance.first(3));
            
            // Write the table as a standard CSV
            employeePerformance.____.csv("employee_performance_standard.csv");
            
            // Write with a semicolon separator
            employeePerformance.write().csv(CsvWriteOptions
                .____("employee_performance_semicolon.csv")
                .____(';')
                .build());
            
            // Write without headers for a legacy system
            employeePerformance.write().csv(CsvWriteOptions
                .builder("employee_performance_noheader.csv")
                .____(____)
                .build());
            
            System.out.println("\nFiles successfully written to output directory.");
            
            Table readBack = Table.read().csv("employee_performance_standard.csv");
            System.out.println("\nVerification - Reading back semicolon-separated file:");
            System.out.println(readBack.first(3));
            
        } catch (Exception e) {
            System.err.println("Error processing CSV files: " + e.getMessage());
        }
    }
}
코드 편집 및 실행