Question

I'm creating a file that isn't really a csv file, but SuperCSV can help me to make the creation of this file easier. The structure of the file uses different lengths for each line, following a layout that don't separate the different information. So, to know which information has in one line you need look at the first 2 characters (the name of the register), count the characters and extract it by size.

I've configured SuperCSV to use empty delimiter, however, the created file is using a space where it should have nothing.

public class TarefaGerarArquivoRegistrosFiscais implements ITarefa {

    private static final CsvPreference FORMATO_ANEXO_IV = new CsvPreference.Builder('"', '\0' , "\r\n").build();

    public void processar() {
        try {
            writer = new CsvListWriter(getFileWriter(), FORMATO_ANEXO_IV);
            writer.write(geradorRegistroU1.gerar());
        } finally {
            if (writer != null)
                writer.close();
        }
    }
}

I'm doing something wrong? '\0' is the correct code for a null char?

Was it helpful?

Solution

It's probably not what you want to hear, but I wouldn't recommend using Super CSV for this (and I'm a committer!). Its sole purpose is to deal with delimited files - and you're not using delimiters.

You could misuse Super CSV by creating a wrapper object (containing your List) whose toString() method simply concatenates all of the values together, then passing that single object to writer.write(), but it's an awful hack.

I'd recommend either finding another library more suited to your problem, or writing your own solution.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top