Java - Relative path of a file in a java web application

前端 未结 6 2010
星月不相逢
星月不相逢 2020-11-29 23:55

I want to read a file from a java web application. I don\'t want to give the absolute path of the file. I just want to put the file in some directory of my web application.<

6条回答
  •  爱一瞬间的悲伤
    2020-11-30 00:29

    The alternative would be to use ServletContext.getResource() which returns a URI. This URI may be a 'file:' URL, but there's no guarantee for that.

    You don't need it to be a file:... URL. You just need it to be a URL that your JVM can read--and it will be.

提交回复
热议问题