so i am reading in a file thats in csv format and then formatting it and outputting it to the console my only problem is it works fine till i hit a string that has spaces in it so i was wondering if there was a way to read the data into a list and have the elements increment if there is a comma so if i have this text file im reading in
000001, Pineweed, Long Bottom Leaf, 600.0 000002, Lembas, Elven Wayfare Bread, 200.0 000003, Wine, Woodland Elf Wine, 400.0 000004, Mushrooms, Farmer Took's Finest, 125.0 000005, Mithril, Enchanted Dwarven Armor, 3000.0
how would i take Long Bottom Leaf as one string if that makes since this is what ive tried
import java.io.*;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileSystemView;
import java.util.ArrayList;
import java.util.Scanner;
public class ProductReader {
public static void main (String[] args) {
ArrayList<String> reader = new ArrayList<String>();
JFileChooser file = new JFileChooser(FileSystemView.getFileSystemView().getHomeDirectory());
int returnValue = file.showOpenDialog(null);
int line = 0;
int end = 0;
int counterID = 0;
int counterProduct = 1;
int counterDescription = 2;
int counterCost = 3;
if (returnValue == JFileChooser.APPROVE_OPTION) {
File selectedFile = file.getSelectedFile();
String fileName = selectedFile.getName();
try {
Scanner fin = new Scanner (selectedFile);
while (fin.hasNext()) {
String data = fin.next();
reader.add (data.replace(",", ""));
}
fin.close();
}
catch (FileNotFoundException e) {
e.printStackTrace();
}
}
System.out.printf ("%s", "ID#");
System.out.printf ("%15s", "Product");
System.out.printf ("%15s", "Description");
System.out.printf ("%15s", "Cost\n");
System.out.print ("==============================================================\n");
for (int x = 0; x < reader.size(); x++) {
if (line == 0) {
System.out.printf ("%-9s", reader.get(counterID));
counterID += 4;
}
if (line == 1) {
System.out.printf ("%-16s", reader.get(counterProduct));
counterProduct += 4;
}
if (line == 2) {
System.out.printf ("%-18s", reader.get(counterDescription));
counterDescription += 4;
}
if (line == 3) {
System.out.print (reader.get(counterCost));
counterCost += 4;
}
end++;
if (reader.size() > end) {
line++;
}
if (line == 4) {
System.out.println();
line = 0;
}
}
}
}