• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to slove this problem

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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()...
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic