-1

We currently doing research on how append files in CSV file with Java programming language.

Therefore, we looking for some input & guidance on this, which will much useful for me.

Your help & guidance will be much appreciated.

Thanks in advance.

Dave
  • 21
  • 1
  • A csv-file is basically a text-file, so how would you expect to append some other file to it? – piet.t Nov 27 '17 at 07:26
  • 1
    You can try base64-encoding of your image file and then appending that to your csv file. Not sure why you would need to do such a thing in the first place though! – anacron Nov 27 '17 at 07:28
  • 1
    This is just a horrible idea. It's a broken solution right from the start. – Kayaman Nov 27 '17 at 08:01

2 Answers2

0

No, there is not, but the reason why is not specific to the Java programming language. Rather, it pertains to the nature of CSV in general.

CSV stands for "comma separated values", and it is a way to store database information in plaintext. If you read RFC 4180, you'll see a formal definition outlined there.

Part of the definition of CSV is that it is stored in plain text. That means that only numbers and strings can be stored in CSV files.

Thus, it is impossible to store image files in CSV files, unless you serialize your images into strings. More info on how to do that is here: Serialize image to a StringHow can I convert an image to a base64 string using Java?.

Saketram Durbha
  • 450
  • 3
  • 14
0

Of course it's possible. All you need is to convert your binary data to a Base 64 string representation.

Apache commons codec does this for you:

Just use:

byte[] binaryData = someMethodToReadYourFileIntoBytes();
String encodedData = Base64.encodeBase64String(binaryData);`

Refer to the javadoc for more information and other options on how to go about it.

Hope it helps.

Jeronimo Backes
  • 6,141
  • 2
  • 25
  • 29