Really not much. The reason I changed the major version number was because we moved from java 5 to java 7. This meant that anyone still using java 5 or java 6 could not upgrade - which to me denotes a major point increment.
Starting with version 3.0 I have kept the change list on this wiki. If you have any questions about past or planned changes since 3.0 please check [What's new] page.
I have had several questions about foreign character sets and found several good articles on stack overflow about dealing with them but unfortunately I have never received feedback on if it worked or not. Here are the links I found if they do help or not please let me know.
https://stackoverflow.com/questions/4964640/reading-inputstream-as-utf-8
http://stackoverflow.com/questions/696626/java-filereader-encoding-issue
https://stackoverflow.com/questions/361975/setting-the-default-java-character-encoding/362006#362006
Here is where opencsv configuration is both a blessing and a curse. When creating a CSVReader, Writer, Parser you can define what the quotation mark and the escape character is (otherwise they default). This is why I will always try and say quotation character instead of quotation mark because you define what opencsv treats as a quotation mark. That said there are two ways to escape a quotation character:
If you see simular to the following:
05-04 16:13:31.821 25829-25829/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.pk.opencsvpoc, PID: 25829
java.lang.NoClassDefFoundError: Failed resolution of: Ljava/beans/Introspector;
It is because Android only ported over a subset of java.beans into its version of java. You can see a list of what is support at https://developer.android.com/reference/java/beans/package-summary
There are plans to switch over to reflection in opencsv 5.0 but I doubt it will remove all our dependencies on java.beans. For now the best suggestion for opencsv is to steer clear of the com.opencsv.bean classes until Android fully supports java.beans or we are successful in removing java.beans.
Another possibility is to try another csv library. I checked apache commons csv and super-csv and apache does not convert to beans but super-csv does using only reflection.
Unless you are dealing with custom csv files my default recommendation is to switch over to the RFC4180Parser. The CSVParser was the original parser for opencsv and predates the RFC4180 specification. It is made for a high degree of customization but there exist data that it, even with all its customizations, it cannot parse. If the data does follow the RFC4180 specification then use the RFC4180Parser - it will be a lot easier to set up and parse.
Hi,
Is there a maximum number of columns that opencsv can create? I am supposed to create a csv file with 1,116 columns, but what got generated was up to 1,000 columns only in supercsv.
I just would like to understand the behavior in opencsv if there's a difference from supercsv.
Thanks.
As many columns as Java can fit in an integer. I think your 1,116 columns are safe.
Good morning,
I want to use CSVWriter or CSVParserWriter to output the file in .csv format (as opposed a .txt, etc). When I look at the .csv file, I want the file to have leading 0s (no converstion of any of my ctring arrays to number. So if I output the following:
String[] array = {"0000001", "02345698", "120", "3" , "10"};
I should see the following cells in my .csv file:
0000001 02345698 120 3 10
currenlty, using writer, I get the following:
1 2345698 120 3 10
Please help, thank you
Would you please open a regular ticket for this and include:
1. Code, and
2. Data?
Hi,
CSVWriter is not writing all the data from the resultset, It is breaking in between. In my resultSet have 4000 record but the csv file is generated with 1401 record, it is breaking in between.
This is intimetent issue, some time it writes whole data and some time its break in between.
I am using StreamingResponseBody with below code:
private double writeToOutputStreamUsingCSVWriter(OutputStream outputStream, ResultSet resultSet,
DownloadMaster downloadMaster) {
double totalBytes = 0;
if (Objects.nonNull(outputStream) && Objects.nonNull(resultSet)) {
try (CountingOutputStream counterStream = new CountingOutputStream(outputStream);
BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(counterStream));
CSVWriter csvWriter = new CSVWriter(bufferedWriter)) {
}
return totalBytes;
}
Could you please help me.
Thanks.
Last edit: Sanjay 2022-06-01
The only thing I can think of offhand is to have a finally statment in the try catch where you flush the writer.
finally {
csvWriter.flush();
}
though in you code you should probably put it between the writeAll and the getByteCount to force the count to be correct..