• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to slove this problem  RSS feed

 
srikanth pidikiti
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi friends
i want to split C:\Documents and Settings\Administrator\Desktop\HotelInfo.pdf using java but Split option is not accepting "\" so how to spit it.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm guessing that's because split uses regular expressions, in which "\" has special meaning. You need to escape it like "\\". And because in Java strings the backslash is used to escaping characters, you need to escape them again, which would make the string you pass to the split routine "\\\\". Hope all the backslashes haven't gotten to my head
 
Rodrigo Alvarez
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why not manipulating it with a File instance ?

File a = new File ("c:\a\b\c.pdf");

=> then you a.getPath(), a.getParent()...
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16049
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rodrigo Alvarez:
[QB]File a = new File ("c:\a\b\c.pdf");


As Ulf explained, that should be:

File a = new File ("c:\\a\\b\\c.pdf");

because the backslash character has a special meaning in Java source code.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!