Last active
November 23, 2023 22:14
-
-
Save vernetto/be338d19faa0021cb9defecf23651490 to your computer and use it in GitHub Desktop.
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
import java.io.BufferedReader; | |
import java.io.FileReader; | |
import java.io.IOException; | |
public class CSVProcessor { | |
public static void main(String[] args) { | |
String filePath = "path/to/your/csvfile.csv"; // Replace with your file path | |
processCSV(filePath); | |
} | |
public static void processCSV(String filePath) { | |
try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) { | |
String line; | |
StringBuilder accumulatedLine = new StringBuilder(); | |
while ((line = reader.readLine()) != null) { | |
accumulatedLine.append(line); | |
// Check if line ends with a comma or is the last line | |
if (!line.endsWith(",")) { | |
// If it doesn't end with a comma, read the next line | |
continue; | |
} | |
// Process the complete line | |
processLine(accumulatedLine.toString()); | |
// Reset the StringBuilder for the next line | |
accumulatedLine.setLength(0); | |
} | |
// Process the last accumulated line if it's not empty | |
if (accumulatedLine.length() > 0) { | |
processLine(accumulatedLine.toString()); | |
} | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
private static void processLine(String line) { | |
// Implement your line processing logic here | |
System.out.println(line); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment