Read text file delimited by pads in JAVA

0

I have a text file of the form:

Pomace oil # 2.11 # 0.21 # 7

Sunflower oil # 5.14 # 0.1 # 3

I need to read and store its contents in different variables, that is, until the first one in one, until the second one in another, etc.

I am using the following line of code to read the file:

Path path = FileSystems.getDefault().getPath(SEPARADOR, "productos.csv");

Where separator is #, but do not continue. Can anybody help me? Thanks.

    
asked by Mario Hernandez 07.12.2017 в 00:10
source

1 answer

0

try:

public class CSVReader {

    public static void main(String[] args) {

        String csvFile = "/Users/mkyong/csv/country.csv";
        String line = "";
        String cvsSplitBy = "#";

        try (BufferedReader br = new BufferedReader(new FileReader(csvFile))) {

            while ((line = br.readLine()) != null) {

                // use comma as separator
                String[] country = line.split(cvsSplitBy);

                // TODO

            }

        } catch (IOException e) {
            e.printStackTrace();
        }

    }

}
    
answered by 07.12.2017 в 01:24