How can I get real path for file in my WebContent folder?

前端 未结 9 987
既然无缘
既然无缘 2020-12-16 02:33

I need to get real path for file in my WebContent directory, so that framework that I use can access that file. It only takes String file as attribute, so I need to get the

9条回答
  •  有刺的猬
    2020-12-16 03:06

    In situations like these I tend to extract the content I need as a resource (MyClass.getClass().getResourceAsStream()), write it as a file to a temporary location and use this file for the other call.

    This way I don't have to bother with content that is only contained in jars or is located somewhere depending on the web container I'm currently using.

提交回复
热议问题