Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. import java.io.File;
  2. import java.io.FileNotFoundException;
  3. import java.util.ArrayList;
  4. import java.util.Arrays;
  5. import java.util.List;
  6. import java.util.Scanner;
  7.  
  8.  
  9. public class TestScanner {
  10.  
  11. public static void main(String[] args) throws FileNotFoundException {
  12. String fileName = "flugtest.csv";
  13. File file = new File(fileName);
  14.  
  15. // this gives you a 2-dimensional array of strings
  16. List<List<String>> lines = new ArrayList<>();
  17. Scanner inputStream;
  18.  
  19. try
  20. {
  21. inputStream = new Scanner(file);
  22.  
  23. while(inputStream.hasNext()){
  24. String line = inputStream.next();
  25. String[] values = line.split(",");
  26.  
  27. // this adds the currently parsed line to the 2-dimensional string array
  28. lines.add(Arrays.asList(values));
  29. }
  30. inputStream.close();
  31. }
  32.  
  33. catch (FileNotFoundException e)
  34. {
  35. e.printStackTrace();
  36. }
  37.  
  38. int lineNo = 1;
  39. for(List<String> line: lines) {
  40. int columnNo = 1;
  41. for (String value: line) {
  42. System.out.println("Line " + lineNo + " Column " + columnNo + ": " + value);
  43. columnNo++;
  44. }
  45. lineNo++;
  46. }
  47.  
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement