Here you can find the source of splitCommand(String command)
public static String[] splitCommand(String command)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.List; public class Main { public static String[] splitCommand(String command) { List<String> elements = new ArrayList<String>(); String[] base = command.split(" "); int realIndex = 0; boolean inString = false; for (int i = 0; i < base.length; i++) { for (int j = 0; j < base[i].length(); j++) { if (base[i].charAt(j) == '"') { if (j == 0) inString = !inString; else if (base[i].charAt(j - 1) != '\\') inString = !inString; }// w w w .java 2 s.co m } if (elements.size() <= realIndex) elements.add(base[i]); else elements.set(realIndex, elements.get(realIndex) + " " + base[i]); if (!inString) realIndex++; } return elements.toArray(new String[0]); } }