Java various path acquisition

foreword

In the process of coding, you may need to obtain the system path anytime and anywhere. I will introduce several ways to obtain it below.

text

web project

Get the root path of the web project, that is, the webapp layer:

request.getRealPath("");

Ordinary item

Get the root path of the project:

File directory = new File("");
directory.getAbsolutePath();

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325958832&siteId=291194637