Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

split() throws PatternsyntaxException

 
naveen yadav
Ranch Hand
Posts: 384
Java MyEclipse IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4567
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
\ is a special character in Java string literals and in regular expressions. Which means you have to escape it twice!
 
naveen yadav
Ranch Hand
Posts: 384
Java MyEclipse IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
bingo !!
thanks Matthew Brown
 
Wendy Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you could also consider using FILE, that has loads of methods to do this sort of stuff.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic