File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

split() throws PatternsyntaxException

 
naveen yadav
Ranch Hand
Posts: 384
Java MyEclipse IDE Spring
  • 0
  • 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: 4549
8
Java Netbeans IDE Scala
  • 0
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
bingo !!
thanks Matthew Brown
 
Wendy Gibbons
Bartender
Posts: 1107
Eclipse IDE Oracle VI Editor
  • 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.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic