[Solved] How to read and edit CSV file using Java Swing? [duplicate]


Reading a CSV is independent from Swing: Swing handle user interfaces but not file input/output. For that, you can use the classes in the java.io package. In particular:

  • the FileReader class to read through your file

  • the BufferedReader class to read one line of your CSV file at a time

  • the StringTokenizer class to parse individual entries in a line (part of java.util)

Then, the easiest way to display this with swing is to store this information inside nested Vector objects (java.util):

  • one top level Vector where each element represents a line and is itself a Vector

  • each Vector representing a line contains the entries for that line

From there, you can create a JTable (javax.swing) to display this information using the constructor

public JTable(Vector rowData, Vector columnNames)

You can see it requires yet another Vector with the names for each column (which must be the same size as the number of entries in a line from your file).

1

solved How to read and edit CSV file using Java Swing? [duplicate]