Advertisement
Guest User

PASTA

a guest
Dec 14th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.94 KB | None | 0 0
  1. import java.nio.file.Files;
  2. import java.nio.file.Path;
  3. import java.nio.file.Paths;
  4. import java.util.Scanner;
  5. import java.util.StringTokenizer;
  6.  
  7. public class Application {
  8.  
  9.     public static void main(String[] args) throws Exception {
  10.         Scanner stdin = new Scanner(System.in);
  11.         System.out.print("Enter CSV file path: ");
  12.         Path path = Paths.get(stdin.nextLine());
  13.         System.out.print("Enter separator [comma by default]: ");
  14.         String separator = stdin.nextLine();
  15.  
  16.         if (separator.isEmpty()) {
  17.             separator = ",";
  18.         }
  19.  
  20.         Scanner file = new Scanner(Files.newInputStream(path));
  21.         while (file.hasNextLine()) {
  22.             String line = file.nextLine();
  23.             StringTokenizer tokenizer = new StringTokenizer(line, separator);
  24.             while (tokenizer.hasMoreTokens()) {
  25.                 System.out.println(tokenizer.nextToken());
  26.             }
  27.         }
  28.     }
  29.  
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement