I am trying to read a CSV file from the web in Java but I only need the first line of the CSV file. That is, I don't really need to download the entire CSV file. How can I do this efficiently? For instance, suppose the CSV is 100mb but I only need the first row which is less than 1kb.
Here's what I am using to download a CSV:
try {
String str = "https://www.websitelink.csv";
BufferedReader reader = new BufferedReader(new InputStreamReader(new URL(str).openStream()));
String line = reader.readLine(); //this is the only line I need (the first line)
} catch (Exception e1) {
e1.printStackTrace();
}
Note, my question is not asking how to read only the first line, it is asking how to download only the first line of a CSV.