Hello Marcus. Though you can still use that constructor for now we have moved to alot of the logic in the reader to a CSVParser class and then added an RFC4180Parser for those who absolutely needed RFC4180 compliance. Because we were adding so many new features instead of coming up with different constructors for all the combinations we created Builder classes. So for your above example where you have a single quote as the quote character and you want to skip a line before reading data (tab is default so not needed for the parser) you would do the following.
/***testbuildingaCSVReaderwithaRFC4180Parserusingthe*appropriatebuilders**@throwsIOExceptionButnotreally*/@TestpublicvoidtestSupportRequest58()throwsIOException{StringBuildersb=newStringBuilder(ICSVParser.INITIAL_READ_SIZE);sb.append("'This','line',should, skip").append("\n").append("a,'''',c").append("\n")// a,',c.append("Second line,'Same as the first\nbut a whole lot longer',and a whole lot worse.").append("\n");RFC4180Parserparser=newRFC4180ParserBuilder().withQuoteChar('\'').build(); CSVReader c = new CSVReaderBuilder(new StringReader(sb.toString())) .withCSVParser(parser) .withSkipLines(1) .build(); String[] nextLine = c.readNext(); assertEquals(3, nextLine.length); assertEquals("a", nextLine[0]); assertEquals(1, nextLine[1].length()); assertEquals("\'", nextLine[1]); assertEquals("c", nextLine[2]); nextLine = c.readNext(); assertEquals(3, nextLine.length); assertEquals("Secondline", nextLine[0]); assertEquals("Sameasthefirst\nbutawholelotlonger", nextLine[1]); assertEquals("andawholelotworse.",nextLine[2]);}
That might seem like alot more but it makes it easier to configure the parser and reader exactly the way you want it.
Hope that helps.
Scott :)
Last edit: Scott Conway 2018-07-02
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Status: open Group: v1.0 (example) Created: Thu Jun 28, 2018 03:03 PM UTC by Marcus Radisch Last Updated: Fri Jun 29, 2018 02:21 AM UTC Owner: Scott Conway
Hello,
i have to read the first line of the csv - file. The
CSVReader reader = new CSVReader(new FileReader("yourfile.csv"), '\t',
'\'', 1); ist marked as deprecated. How do i is now withe the
opencsv-libary?
Status: open Group: v1.0 (example) Created: Thu Jun 28, 2018 03:03 PM UTC by Marcus Radisch Last Updated: Fri Jun 29, 2018 02:21 AM UTC Owner: Scott Conway
Hello,
i have to read the first line of the csv - file. The
CSVReader reader = new CSVReader(new FileReader("yourfile.csv"), '\t',
'\'', 1); ist marked as deprecated. How do i is now withe the
opencsv-libary?
Status: open Group: v1.0 (example) Created: Thu Jun 28, 2018 03:03 PM UTC by Marcus Radisch Last Updated: Fri Jun 29, 2018 02:21 AM UTC Owner: Scott Conway
Hello,
i have to read the first line of the csv - file. The
CSVReader reader = new CSVReader(new FileReader("yourfile.csv"), '\t',
'\'', 1); ist marked as deprecated. How do i is now withe the
opencsv-libary?
Status: open Group: v1.0 (example) Created: Thu Jun 28, 2018 03:03 PM UTC by Marcus Radisch Last Updated: Fri Jun 29, 2018 02:23 AM UTC Owner: Scott Conway
Hello,
i have to read the first line of the csv - file. The
CSVReader reader = new CSVReader(new FileReader("yourfile.csv"), '\t',
'\'', 1); ist marked as deprecated. How do i is now withe the
opencsv-libary?
Thanks our CSV parser is now in pre alpha... Is there any plan for setting
up the encoding we get some file with German Letter Like äöüß....
If Files are saved in ISO and not in utf8 I get cryptic signs in the read
data.
Status: open Group: v1.0 (example) Created: Thu Jun 28, 2018 03:03 PM UTC by Marcus Radisch Last Updated: Fri Jun 29, 2018 02:21 AM UTC Owner: Scott Conway
Hello,
i have to read the first line of the csv - file. The
CSVReader reader = new CSVReader(new FileReader("yourfile.csv"), '\t',
'\'', 1); ist marked as deprecated. How do i is now withe the
opencsv-libary?
Status: open Group: v1.0 (example) Created: Thu Jun 28, 2018 03:03 PM UTC by Marcus Radisch Last Updated: Fri Jun 29, 2018 02:23 AM UTC Owner: Scott Conway
Hello,
i have to read the first line of the csv - file. The
CSVReader reader = new CSVReader(new FileReader("yourfile.csv"), '\t',
'\'', 1); ist marked as deprecated. How do i is now withe the
opencsv-libary?
Status: open Group: v1.0 (example) Created: Thu Jun 28, 2018 03:03 PM UTC by Marcus Radisch Last Updated: Mon Jul 02, 2018 11:53 PM UTC Owner: Scott Conway
Hello,
i have to read the first line of the csv - file. The
CSVReader reader = new CSVReader(new FileReader("yourfile.csv"), '\t',
'\'', 1); ist marked as deprecated. How do i is now withe the
opencsv-libary?
Hello Marcus. Sorry it took so long to reply. Have been very busy with
work and home remodeling.
To answer your question we are characterset neutral - it is up to you to
determine the character set.
If you know the character set what you would do is in the CSVReaderBuilder
you would pass in an InputStreamReader instead of a FileReader. An example
of this is in the CSVReaderTest.
@Test
public void issue108ReaderPlaysWellWithChannels() throws IOException {
byte[] bytes = "name\r\nvalue\r\n".getBytes("UTF-8");
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
ReadableByteChannel ch = Channels.newChannel(bais);
InputStream in = Channels.newInputStream(ch);
InputStreamReader reader = new InputStreamReader(in,
Charset.forName("UTF-8"));
CSVReaderBuilder builder = new CSVReaderBuilder(reader);
CSVReader csv = builder.withVerifyReader(false).build();
assertEquals(2, csv.readAll().size());
}
As for determining the character encoding there are several articles to
help you there. You will just need to open up the file beforehand just to
get the encoding.
Thanks our CSV parser is now in pre alpha... Is there any plan for setting
up the encoding we get some file with German Letter Like äöüß....
If Files are saved in ISO and not in utf8 I get cryptic signs in the read
data.
Greetings Marcus
Scott Conway sconway@users.sourceforge.net schrieb am Di., 3. Juli 2018,
22:43:
Not a problem - glad you got it running.
Scott :)
On Mon, Jul 2, 2018 at 3:06 AM Marcus Radisch
amarradi@users.sourceforge.net wrote:
Hey Scott,
sorry it runs..... my mistake. The Parser ist not the ParserBuilder()....
Marcus
2018-07-02 9:49 GMT+02:00 Marcus Radisch radischm@gmail.com:
Hey Scott,
thanks for your help!
Now i tried your Tip in my Code i get two errors... 'cannot find symbol
method withSeparator(char)' in the line
RFC4180Parser parser = new
RFC4180ParserBuilder().withSeparator('\'').build();
and in the CSVReader 'cannot find symbol method withSkipLines(1)'
The Version we use is the opencsv-4.2.jar
Whats wrong there?
Marcus
2018-06-29 4:23 GMT+02:00 Scott Conway sconway@users.sourceforge.net:
Status: open Group: v1.0 (example) Created: Thu Jun 28, 2018 03:03 PM UTC by Marcus Radisch Last Updated: Fri Jun 29, 2018 02:21 AM UTC Owner: Scott Conway
Hello,
i have to read the first line of the csv - file. The
CSVReader reader = new CSVReader(new FileReader("yourfile.csv"), '\t',
'\'', 1); ist marked as deprecated. How do i is now withe the
opencsv-libary?
Status: open Group: v1.0 (example) Created: Thu Jun 28, 2018 03:03 PM UTC by Marcus Radisch Last Updated: Fri Jun 29, 2018 02:23 AM UTC Owner: Scott Conway
Hello,
i have to read the first line of the csv - file. The
CSVReader reader = new CSVReader(new FileReader("yourfile.csv"), '\t',
'\'', 1); ist marked as deprecated. How do i is now withe the
opencsv-libary?
Status: open Group: v1.0 (example) Created: Thu Jun 28, 2018 03:03 PM UTC by Marcus Radisch Last Updated: Mon Jul 02, 2018 11:53 PM UTC Owner: Scott Conway
Hello,
i have to read the first line of the csv - file. The
CSVReader reader = new CSVReader(new FileReader("yourfile.csv"), '\t',
'\'', 1); ist marked as deprecated. How do i is now withe the
opencsv-libary?
Status: open Group: v1.0 (example) Created: Thu Jun 28, 2018 03:03 PM UTC by Marcus Radisch Last Updated: Mon Jul 02, 2018 11:53 PM UTC Owner: Scott Conway
Hello,
i have to read the first line of the csv - file. The
CSVReader reader = new CSVReader(new FileReader("yourfile.csv"), '\t',
'\'', 1); ist marked as deprecated. How do i is now withe the
opencsv-libary?
Sorry I realized my code used separator instead of quote char. The withSkipLines is in the CSVReaderBuilder not the CSVReader. I changed my code example to a unit test that I see building and passing. Try that and see if that helps.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello Marcus. Though you can still use that constructor for now we have moved to alot of the logic in the reader to a CSVParser class and then added an RFC4180Parser for those who absolutely needed RFC4180 compliance. Because we were adding so many new features instead of coming up with different constructors for all the combinations we created Builder classes. So for your above example where you have a single quote as the quote character and you want to skip a line before reading data (tab is default so not needed for the parser) you would do the following.
That might seem like alot more but it makes it easier to configure the parser and reader exactly the way you want it.
Hope that helps.
Scott :)
Last edit: Scott Conway 2018-07-02
Hey Scott,
thanks for your help!
Now i tried your Tip in my Code i get two errors... 'cannot find symbol
method withSeparator(char)' in the line
RFC4180Parser parser = new RFC4180ParserBuilder().withSeparator('\'').build();
and in the CSVReader 'cannot find symbol method withSkipLines(1)'
The Version we use is the opencsv-4.2.jar
Whats wrong there?
Marcus
2018-06-29 4:23 GMT+02:00 Scott Conway sconway@users.sourceforge.net:
Related
Support Requests:
#58Hey Scott,
sorry it runs..... my mistake. The Parser ist not the ParserBuilder()....
Marcus
2018-07-02 9:49 GMT+02:00 Marcus Radisch radischm@gmail.com:
Related
Support Requests:
#58Not a problem - glad you got it running.
Scott :)
On Mon, Jul 2, 2018 at 3:06 AM Marcus Radisch amarradi@users.sourceforge.net wrote:
--
Scott Conway
scott.conway@gmail.com
http://www.conwayfamily.name
Related
Support Requests:
#58Thanks our CSV parser is now in pre alpha... Is there any plan for setting
up the encoding we get some file with German Letter Like äöüß....
If Files are saved in ISO and not in utf8 I get cryptic signs in the read
data.
Greetings Marcus
Scott Conway sconway@users.sourceforge.net schrieb am Di., 3. Juli 2018,
22:43:
Related
Support Requests:
#58Hello Marcus. Sorry it took so long to reply. Have been very busy with
work and home remodeling.
To answer your question we are characterset neutral - it is up to you to
determine the character set.
If you know the character set what you would do is in the CSVReaderBuilder
you would pass in an InputStreamReader instead of a FileReader. An example
of this is in the CSVReaderTest.
@Test
public void issue108ReaderPlaysWellWithChannels() throws IOException {
byte[] bytes = "name\r\nvalue\r\n".getBytes("UTF-8");
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
ReadableByteChannel ch = Channels.newChannel(bais);
InputStream in = Channels.newInputStream(ch);
InputStreamReader reader = new InputStreamReader(in,
Charset.forName("UTF-8"));
CSVReaderBuilder builder = new CSVReaderBuilder(reader);
CSVReader csv = builder.withVerifyReader(false).build();
assertEquals(2, csv.readAll().size());
}
And stack overflow has a good article about creating an InputStreamReader
for a file
https://stackoverflow.com/questions/26280820/java-open-and-read-file-using-inputstreamreader.
As for determining the character encoding there are several articles to
help you there. You will just need to open up the file beforehand just to
get the encoding.
https://stackoverflow.com/questions/499010/java-how-to-determine-the-correct-charset-encoding-of-a-stream
https://www.tutorialspoint.com/java/io/inputstreamreader_getencoding.htm
https://gmigdos.wordpress.com/2010/04/08/java-how-to-auto-detect-a-files-encoding/
I would start with the stackoverflow as they point out existing libraries
that detect encoding - the others are do it yourself.
Hope that helps.
Scott :)
On Fri, Jul 13, 2018 at 4:20 AM Marcus Radisch amarradi@users.sourceforge.net wrote:
--
Scott Conway
scott.conway@gmail.com
http://www.conwayfamily.name
Related
Support Requests:
#58Sorry I realized my code used separator instead of quote char. The withSkipLines is in the CSVReaderBuilder not the CSVReader. I changed my code example to a unit test that I see building and passing. Try that and see if that helps.
Closed for lack of a response.