• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Bear Bibeault
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Jj Roberts

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

 
Ranch Hand
Posts: 670
  • Mark post as helpful
  • send pies
  • 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: 22042
113
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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: 670
  • Mark post as helpful
  • send pies
  • 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: 22042
113
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • 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: 1979
13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about using c:\\User\\abc\\foldername\\ in application.properties?
 
Where does a nanny get ground to air missles? Protect this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic