-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
51 additions
and
1 deletion.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
example/src/main/java/example/ExampleCsvReaderWithClasspathInput.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package example; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.io.Reader; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
import de.siegmar.fastcsv.reader.CsvReader; | ||
import de.siegmar.fastcsv.reader.CsvRecord; | ||
|
||
/** | ||
* Example for reading CSV data from a file in the classpath. | ||
*/ | ||
public class ExampleCsvReaderWithClasspathInput { | ||
|
||
public static void main(final String[] args) throws IOException { | ||
try (CsvReader<CsvRecord> csv = CsvReader.builder().build(getReader("/example.csv"))) { | ||
for (final CsvRecord csvRecord : csv) { | ||
System.out.println(csvRecord.getFields()); | ||
} | ||
} | ||
} | ||
|
||
private static Reader getReader(final String name) { | ||
final InputStream in = ExampleCsvReaderWithClasspathInput.class.getResourceAsStream(name); | ||
if (in == null) { | ||
throw new IllegalStateException("Resource not found: " + name); | ||
} | ||
return new InputStreamReader(in, StandardCharsets.UTF_8); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters