This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Mastering Corda: Blockchain for Java Developers and have Jamiel Sheikh on-line!
See this thread for details.
Win a copy of Mastering Corda: Blockchain for Java Developers this week in the Cloud/Virtualization 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

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

 
Ranch Hand
Posts: 717
  • 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: 22055
113
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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: 717
  • 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: 22055
113
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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: 2008
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?
 
Yeah, but does being a ninja come with a dental plan? And what about this tiny ad?
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic