Java Scanner Usage pathTokenList(String path)

Here you can find the source of pathTokenList(String path)

Description

path Token List

License

Open Source License

Declaration

public static List<String> pathTokenList(String path) 

Method Source Code

//package com.java2s;
/* The MIT License (MIT)
 * Copyright (c) 2014 Nicholas Wright/*from w  w w. ja  v  a 2 s. c o m*/
 * http://opensource.org/licenses/MIT
 */

import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static List<String> pathTokenList(String path) {
        LinkedList<String> resultList = new LinkedList<String>();

        Scanner scanner = new Scanner(path);
        scanner.useDelimiter("\\\\");
        // to handle network paths
        if (path.startsWith("\\\\")) {
            int endPos = path.indexOf("\\", 2);
            resultList.add(path.substring(0, endPos));
            scanner.next();
            scanner.next();
        }

        while (scanner.hasNext()) {
            resultList.add(scanner.next());
        }

        // check if the last entry (filename) has an extension, if so, split them
        if (resultList.peekLast() != null && resultList.peekLast().contains(".")) {
            String lastEntry = resultList.pollLast();
            int dotPosition = lastEntry.lastIndexOf(".");

            String filename = lastEntry.substring(0, dotPosition);
            String extension = lastEntry.substring(dotPosition);

            resultList.add(filename);
            resultList.add(extension);
        }

        scanner.close();

        return resultList;

    }
}

Related

  1. parse_str_vector(String str_vector)
  2. parseDailyData(final List lines, final List priceValues, final List dailyPriceDate)
  3. parseExperimentName(String name)
  4. parseQueryString(String queryString)
  5. parseTime(String input)
  6. pressEnterToContinue()
  7. processLine(String aLine)
  8. queryMenu(Scanner in, String msg, LinkedList options)
  9. queryStr(Scanner in, String msg)