java 如何将图像添加到 CSV 文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12929762/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 10:49:39  来源:igfitidea点击:

How can I add an image to a CSV file?

javaimagecsv

提问by Nitesh Verma

I need to write an image on a .csv file with some data. Writing data was simple but I cant write an image into it which is stored on the hard disk. I am using FileWriterclass to implement this and .append();to add items in the file. How can I add an image to a CSV file?

我需要用一些数据在 .csv 文件上写一个图像。写入数据很简单,但我无法将存储在硬盘上的图像写入其中。我正在使用FileWriter类来实现这一点并.append();在文件中添加项目。如何将图像添加到 CSV 文件?

回答by MadProgrammer

CSV is a text based file format, where as an images are binary data, the two don't mix well.

CSV 是一种基于文本的文件格式,由于图像是二进制数据,因此两者不能很好地混合。

You'd be better of supplying a reference to the images (relative path and name) and bundling them together.

您最好提供对图像的引用(相对路径和名称)并将它们捆绑在一起。

回答by James Bassett

Based on your comments, you'd be better off storing a text representation of your barcode (along with the other information, such as product name, price, etc) in the CSV file (instead of embedding the image or filename).

根据您的评论,您最好将条形码的文本表示(以及其他信息,例如产品名称、价格等)存储在 CSV 文件中(而不是嵌入图像或文件名)。

Then when reading the CSV file, you can use an open source library such as Barbecueto dynamically generate the barcode image. Barbecue supports a wide range of barcode and image formats.

然后在读取CSV文件时,可以使用Barbecue等开源库动态生成条码图片。Barbecue 支持多种条形码和图像格式。