Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.List;
- import java.util.Scanner;
- public class TestScanner {
- public static void main(String[] args) throws FileNotFoundException {
- String fileName = "flugtest.csv";
- File file = new File(fileName);
- // this gives you a 2-dimensional array of strings
- List<List<String>> lines = new ArrayList<>();
- Scanner inputStream;
- try
- {
- inputStream = new Scanner(file);
- while(inputStream.hasNext()){
- String line = inputStream.next();
- String[] values = line.split(",");
- // this adds the currently parsed line to the 2-dimensional string array
- lines.add(Arrays.asList(values));
- }
- inputStream.close();
- }
- catch (FileNotFoundException e)
- {
- e.printStackTrace();
- }
- int lineNo = 1;
- for(List<String> line: lines) {
- int columnNo = 1;
- for (String value: line) {
- System.out.println("Line " + lineNo + " Column " + columnNo + ": " + value);
- columnNo++;
- }
- lineNo++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement