to Csv Record - Java File Path IO

Java examples for File Path IO:CSV File

Description

to Csv Record

Demo Code


//package com.java2s;

public class Main {

    public static final String CSV_SEP = ",";

    public static String toCsvRecord(String... fields) {
        StringBuilder buf = new StringBuilder();
        if (fields != null) {
            for (int i = 0; i < fields.length; i++) {
                if (i != 0) {
                    buf.append(CSV_SEP);
                }/*from ww  w  . ja v a  2  s .c om*/
                buf.append(enclose(fields[i]));
            }
        }
        return buf.toString();
    }

    public static String enclose(String field) {
        return "\"" + field + "\"";
    }
}

Related Tutorials