• 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
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

Why the path returns doesn't return the correct one as specified in applicaiton.properties?

 
Ranch Hand
Posts: 947
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi experts,

I have been trying many days to get the image to be inserted into a path that I specified in the application.properties but to no avail.

And I am not sure where I had done wrongly such that when I printed out the path it would not include the the last / and so the image will not get into the folder but append to the last part of the path and not after the /






Here's the applicaiton.properties:


To be more clear,

my path is C:\User\abc\foldername\

So for the calss FileStorageProperties it will give me the exact path as put in the application.properties

but when I print out the controller it will just print C:\User\abc\foldername and the image name will append right after foldername

I am exhausted and I am beaten.

I am not sure what to do now and it is like nobody can help me cos everyone said all the answers are in the internet but really I have tried so hard I still can't get it right.

Please help me.

Tks.
 
Sheriff
Posts: 22716
129
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It could be caused by the properties parsing that uses \ as an escape character.

It the only issue is that the directory is missing a trailing \, then the solution is actually quite simple. Don't use string concatenation, use Path.resolve:

 
tangara goh
Ranch Hand
Posts: 947
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Spoor wrote:It could be caused by the properties parsing that uses \ as an escape character.

It the only issue is that the directory is missing a trailing \, then the solution is actually quite simple. Don't use string concatenation, use Path.resolve:



Hi Rob,

Thanks.

I'd like to know if this code is used in the cloud ... I mean if the app is being hosted on the cloud and say if I changed the C:\ blah blah blah to a location in the db in the cloud, will it work or I need to take note of further configuration and the API being used.

What are those ?
 
Rob Spoor
Sheriff
Posts: 22716
129
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
With the resolve method, it will resolve the file relative to the path. Windows supports both \ and / for directory separators, Linux only /. As long as you don't have any \ in the path to resolve, the method should do the same on both Windows and Linux.
 
Bartender
Posts: 2266
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How about using c:\\User\\abc\\foldername\\ in application.properties?
reply
    Bookmark Topic Watch Topic
  • New Topic