LoginSignup
0
3

More than 3 years have passed since last update.

Javaで実行しているディレクトリの絶対パスを取得する方法

Last updated at Posted at 2020-01-19

はじめに

Qiita初投稿です。

環境

java1.8.0_221

やりたいこと

C:\Users\Miyayu\IDEA\example\example.jarを実行しているとする。
C:\Users\Miyayu\IDEA\example(String型)を取り出したい。

コード

FileSystems.getDefault().getPath("").toAbsolutePath().toString()

これだけ!かんたんでしょ?

指定したファイルの絶対パスを知りたいときは

.\expdir\hoge.jsonの絶対パスを知りたい

FileSystems.getDefault().getPath("expdir","hoge.json").toAbsolutePath().toString()
0
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
3