0

I have a question:

I'm trying to convert my CSV file to XML file and I'm seeing the response of this post: Java lib or app to convert CSV to XML file?

I see that I need use this OpenCSV library and in particular, I must use this code:

CSVReader reader = new CSVReader(new FileReader(startFile));

where String startFile = "./startData.csv";

Now, I don't get a String as startFile, but I have a byte[] because, for other question, I have convert my file in byte[]. How can I use this code with byte[]?

Are there alternatives?

Thanks

Community
  • 1
  • 1
Musich87
  • 562
  • 1
  • 12
  • 31

1 Answers1

6

Since CSVReader's constructor takes a Reader as parameter, you can pretty much pass anything that's readable to it.

So in your case, you may try using a bytes stream reader, as in:

CSVReader reader = new CSVReader(
    new InputStreamReader(
        new ByteArrayInputStream(yourByteArray)));
Kilazur
  • 3,089
  • 1
  • 22
  • 48