Win a copy of React Cookbook: Recipes for Mastering the React Framework this week in the HTML Pages with CSS and JavaScript forum!
  • 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
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

How to get the file path right?

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a path to a file which consists of two parts

for e.g.


getDocument(docroot + location)

Now i want to insert a sub path between docroot and location like this


So i did this:



But now i get


It still find the file (why?)


But obviously this is not correct. So how do you this right?
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It finds the file because Java isn't terribly fussy about the file separator. You get the result you got because first you replace the backslashes, the "correct" Windows path separator, with forward slashes. When you construct your own path segment you use File.separator, which is the system-specific separator, which is the backslash on windows.
 
Dennis Zandvliet
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

David Newton wrote:It finds the file because Java isn't terribly fussy about the file separator. You get the result you got because first you replace the backslashes, the "correct" Windows path separator, with forward slashes. When you construct your own path segment you use File.separator, which is the system-specific separator, which is the backslash on windows.



Sorry i did this



 
What do you have to say for yourself? Hmmm? Anything? And you call yourself a tiny ad.
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic