It's not a secret anymore!
The moose likes Beginning Java and the fly likes split() throws PatternsyntaxException Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "split() throws PatternsyntaxException" Watch "split() throws PatternsyntaxException" New topic
Author

split() throws PatternsyntaxException

naveen yadav
Ranch Hand

Joined: Oct 23, 2011
Posts: 380

hi ranchers,

i have a String of a location like "dir\\filename" .I want to separate the directory name from file name for which i use the following code



But it throws PatternsyntaxException. why ? it seems to me that split() having a problem with "\\".
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 3793
    
    1

\ is a special character in Java string literals and in regular expressions. Which means you have to escape it twice!
naveen yadav
Ranch Hand

Joined: Oct 23, 2011
Posts: 380

bingo !!
thanks Matthew Brown
Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1098

you could also consider using FILE, that has loads of methods to do this sort of stuff.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: split() throws PatternsyntaxException
 
Similar Threads
I'm Confused : How does this work
PatternSyntaxException
about criteriaFind
replaceAll("+"," ")
char cannot be dereferenced