String line = "Extracting from E:\\Junk\\morejunk\\file.txt";
	System.out.println(line);	//prints:    Extracting from E:\Junk\morejunk\file.txt
	String[] splitPath = line.split("\\");	//exception thrown here
	String folder = splitPath[splitPath.length-2];

Exception in thread "AWT-EventQueue-0" java.util.regex.PatternSyntaxException: Unexpected internal error near index 1

My objective is to always print the folder containing the file being extracted (morejunk in this case).

Any suggestions why it wont accept "\\" as a pattern which is correctly syntaxed?

hmm... well thats funny..

You are correct.. Here I specified the cmd with 2 \'s, but ur way also works when line is given as a paramater, using only 1 \'s.

I guess java automatically throws in another \ on its own every time it sees only 1 \ so \\\\ works.

Thank you.

I suposse, in "\\\\" are three kinds of character, one original \ and two meta characters in order m2,m1,m2,orig.

This question has already been answered. Start a new discussion instead.