2017-10-31 5 views
0

CSV를 읽고 쓰려면 CSVPrinter를 사용하고 있습니다. CSV를 작성하는 동안 "x", "y"(두 번째 열)와 같은 빈 열을 작성하고 싶습니다. 그러나 불행히도 "x", "", "y"로 기록됩니다. CSVPrinter를 사용하여 빈 열을 어떻게 쓸 수 있습니까? 나는 그것을 쓰기 위해 다음과 같은 것들을 사용했다. 심지어 CSVPrinter 설명서에서 찾을 수 없었습니다. 도와주세요.apache.commons.csv의 CSVPrinter로 빈 열을 작성하는 방법

printer.print (널) -> "" printer.print ("") -> ""

감사

+0

사용중인 CSV 형식을 게시하십시오. 기본 출력은 다릅니다. –

답변

0

만 버전 1.5에서 추가되었다 찾고있는 행동 :

CSVFormat customFormat = CSVFormat.DEFAULT 
      .withQuoteMode(QuoteMode.ALL_NON_NULL); 

    CSVPrinter printer = new CSVPrinter(System.out, customFormat); 
    printer.print("x"); 
    printer.print(""); 
    printer.print(null); 
    printer.print("y"); 
    printer.println(); 

: 당신이 ALL_NON_NULL 인용 모드를 적용 할 수 있습니다이 API와

<dependency> 
     <groupId>org.apache.commons</groupId> 
     <artifactId>commons-csv</artifactId> 
     <version>1.5</version> 
    </dependency> 

출력 :

"x","",,"y"