Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

201
Vistas
Generate string content for CSV with Apache Commons in Java instead of writing an actual file

in my Java program, I would like to use the Apache Commons library to generate the content of a CSV file, but not actually creating the file.

I only want to have the String content of the file, and later, write the file using that content using an existing method.

However in all examples of code, it is necessary to define in the target csv file before hand, giving its path and name, but I don't have it, at this moment of the program flow. Is it possible to just get the String for the future csv file, and handle the real file creation independently? Thank you.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

StringWriter

You need the file when you want to write to the file. You could pass the file's content around your programm or store it somewhere until you want to write to the file.

However if you want to write your CSV to String and not to a File you could try to use a StringWriter instead of a FileWriter.

Something like (not compiled, might not be complete)

StringWriter stringWriter = new StringWriter();
CSVPrinter csvPrinter = new CSVPrinter(stringWriter , CSVFormat.DEFAULT
                .withHeader("Header1", "Header2"));
csvPrinter.printRecord("abc", "ghf");
String csvString = stringWriter.toString();
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda