You can construct an InputStreamReader from that InputStream

new InputStreamReader(myInputStream, encoding)

Where myInputStream is your InputStream and encoding is a String that defines the encoding used by your datasource.

You can call your CSVReader like this:

new CSVReader(new InputStreamReader(myInputStream, encoding));
Answer from oers on Stack Overflow
🌐
DZone
dzone.com › data engineering › databases › how to read a large csv file with java 8 and stream api
How to Read a Large CSV File With Java 8 and Stream API
September 28, 2016 - The following code will read the ... ArrayList<YourJavaItem>(); try{ File inputF = new File(inputFilePath); InputStream inputFS = new FileInputStream(inputF); BufferedReader br = new BufferedReader(new InputStreamReader(inputFS)); ...
🌐
Java67
java67.com › 2015 › 08 › how-to-load-data-from-csv-file-in-java.html
How to load data from CSV file in Java - Example | Java67
To read the CSV file we are going to use a BufferedReader in combination with a FileReader. FileReader is used to read a text file in the platform's default character encoding, if your file is encoded in other character encodings then you should ...
🌐
Mkyong
mkyong.com › home › java › how to read and parse csv file in java
How to read and parse CSV file in Java - Mkyong.com
December 26, 2020 - String line; InputStream is = OpenCsvExample.class.getClassLoader().getResourceAsStream("csv/country.csv"); try(BufferedReader br = new BufferedReader(new InputStreamReader(is))){ while((line=br.readLine())!=null){ // process the line } } ... Thanks ...
🌐
Vaadin
vaadin.com › blog › read-and-display-a-csv-file-in-java
Read and Display a CSV File in Java | Vaadin
March 7, 2022 - CSVParser parser = new CSVParserBuilder().withSeparator(';').build(); CSVReader reader = new CSVReaderBuilder(new InputStreamReader(resourceAsStream)).withCSVParser(parser).build(); try { List<String[]> entries = reader.readAll(); String[] headers = entries.get(0); grid.removeAllColumns(); for (int i = 0; i < headers.length; i++) { int colIndex = i; grid.addColumn(row -> row[colIndex]) .setHeader(SharedUtil.camelCaseToHumanFriendly(headers[colIndex])); } grid.setItems(entries.subList(1, entries.size())); } catch (IOException | CsvException e) { e.printStackTrace(); } } }
🌐
GitHub
gist.github.com › nileshdarade › 72913b6272fc07144e40a2561d474de2
Read CSV file using java8 stream · GitHub
I've tried so many elements of reading CSV, but nothing of those are consistent with my works. Now, I can go next steps. ... a silly comment , but we can rewrite values.forEach(value -> System.out.println(value) bit more concise ... try (BufferedReader buffer = new BufferedReader(new InputStreamReader(input))) { return buffer.lines().map(line -> Arrays.asList(line.split(","))) .collect(Collectors.toList()); } }
🌐
Medium
konfhub.medium.com › how-to-process-csv-files-in-java-with-streams-a69221ae46e6
How to Process CSV Files in Java with Streams | by KonfHub | Medium
October 18, 2019 - var filePath = System.getProperty("user.dir") + "/resources/airquality.csv"; Files.lines(Paths.get(filePath)) .skip(0) // ignore the first entry .filter(line -> line.startsWith("India,Bihar")) .forEach(System.out::println); That’s certainly short & sweet, isn’t it! It is higher-level. Given the file path, we say read the lies, skip the first entry, filter away the lines that don’t start with the prefix “India,Bihar” and print the entries to console! Functional. This utilizes the streams approach in Java.
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › 70465746 › method-reads-csv-input-stream-differently-than-csv-file
java - Method reads csv input stream differently than csv file - Stack Overflow
CSVReader reader = new CSVReader(new InputStreamReader(csvData)); String[] line; int bookNum = 1, lineNum = 2; // skip headers while ((line = reader.readNext()) != null) { // map line String productCode = line[0]; String author = line[1]; String ...
Top answer
1 of 5
20

Rather than reinventing the wheel you could have a look at OpenCSV which supports reading and writing of CSV files. Here are examples of reading & writing

2 of 5
1

The spreadsheet contains names, phone numbers, email addresses, etc. And the program lists everyone's data, and when you click on them it brings up a page with more detailed information, also pulled from the CSV. On that page you can edit the data, and I want to be able to click a "Save Changes" button, then export the data back to its appropriate line in the CSV--or delete the old one, and append the new.

The content of a file is a sequence of bytes. CSV is a text based file format, i.e. the sequence of byte is interpreted as a sequence of characters, where newlines are delimited by special newline characters.

Consequently, if the length of a line increases, the characters of all following lines need to be moved to make room for the new characters. Likewise, to delete a line you must move the later characters to fill the gap. That is, you can not update a line in a csv (at least not when changing its length) without rewriting all following lines in the file. For simplicity, I'd rewrite the entire file.

Since you already have code to write and read the CSV file, adapting it should be straightforward. But before you do that, it might be worth asking yourself if you're using the right tool for the job. If the goal is to keep a list of records, and edit individual records in a form, programs such as Microsoft Access or whatever the Open Office equivalent is called might be a more natural fit. If you UI needs go beyond what these programs provide, using a relational database to keep your data is probably a better fit (more efficient and flexible than a CSV).

🌐
Simplesolution
simplesolution.dev › java-read-and-parse-csv-file-using-apache-commons-csv
Read and Parse CSV File in Java using Apache Commons CSV
args) { try { String csvFileName = "D:\\SimpleSolution\\Customers.csv"; CSVFormat csvFormat = CSVFormat.DEFAULT.withFirstRecordAsHeader().withIgnoreHeaderCase(); InputStream inputStream = new FileInputStream(csvFileName); CSVParser csvParser ...
🌐
LabEx
labex.io › tutorials › java-reading-a-csv-file-117982
How to Read a CSV File in Java | LabEx
BufferedReader is a class that reads text from a character-input stream, buffering characters to provide efficient reading of characters, arrays, and lines. The buffer size can be specified, or the default size can be used.
🌐
How to do in Java
howtodoinjava.com › home › i/o › parse and read a csv file in java
Parse and Read a CSV File in Java
September 14, 2022 - In Java, there are different ways of reading and parsing CSV files. Let's discuss some of the best approaches such as OpenCSV, Super CSV etc.
🌐
Coderanch
coderanch.com › t › 771950 › java › Reading-csv-file
Reading csv file (I/O and Streams forum at Coderanch)
April 18, 2023 - Welcome to the Ranch In most real‑life applications one wouldn't read a CSV directly, but use a program designed to cope with CSVs. Obviously your assignment forces you to read the file “by hand”. How you do that depends on the format of the file and what delimiters you are using.
🌐
Medium
medium.com › @zakariafarih142 › mastering-csv-parsing-in-java-comprehensive-methods-and-best-practices-a3b8d0514edf
Mastering CSV Parsing in Java: Comprehensive Methods and Best Practices | by Zakariafarih | Medium
November 25, 2024 - Simple CSV Files: For straightforward CSV files without embedded commas or quotes, basic file reading or the Scanner class suffices. Complex CSV Structures: When dealing with complex CSVs, external libraries like OpenCSV or Apache Commons CSV ...
🌐
Medium
medium.com › @piyushkag1010 › how-to-fetch-a-csv-file-using-java-code-9a84db130b72
How to Fetch a CSV File Using Java Code | by Piyushkag | Medium
September 7, 2023 - import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.URL; import java.nio.charset.StandardCharsets; public class CSVFileFetcher { public static void main(String[] args) { try { String csvUrl = “https://example.com/data.csv"; // Replace with the URL of your CSV file · URL url = new URL(csvUrl); BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream(), StandardCharsets.UTF_8)); CSVParser csvParser = CSVFormat.DEFAULT.withHeader().parse(reader);
🌐
Alex Codes
ale.hashnode.dev › read-csv-file-in-java
Read Csv File In Java - Alex Codes
December 1, 2023 - The CsvSchema is needed to map the values in the csv to our pojo, we could build a CsvSchema programmatically, but is quicker to read it from the file. remember we don't need all columns in the csv? that is very common in real life. We need to tell jackson not to fail when encountering a field that is not present in the model. Jackson can accept a variety of inputs: InputStream, File, Reader, String (csv content)
🌐
TechVidvan
techvidvan.com › tutorials › read-csv-file-in-java
How to Read CSV file in Java - TechVidvan
July 1, 2020 - We use the CSVReader class to read a CSV file. The class CSVReader provides a constructor to parse a CSV file. ... 1: Create a class file with the name CSVReaderDemo and write the following code.
🌐
Codersarts
codersarts.com › post › how-to-read-csv-file-and-display-data-into-table-format-by-using-java-swing
How to read .CSV file and display data into table format by using Java Swing?
July 23, 2021 - In this blog,we build a GUI application which read .csv file and display into table by using java swing. ... import javax.swing.*; import javax.swing.table.DefaultTableModel; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import java.io.FileInputStream; import java.io.InputStreamReader; import java.util.Vector; import org.apache.commons.csv.CSVFormat; import org.apache.commons.csv.CSVRecord; public class SwingTableExample { public static void main(String args[]) { JFrame frame = new JFrame("Java Swing Table"); JLabel selected_file = new JLabel();