Here you can find the source of pathTokenList(String path)
public static List<String> pathTokenList(String path)
//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; } }