How to get the absolute path of a directory running in Java

Introduction

This is Qiita's first post.

environment

java1.8.0_221

Thing you want to do

Suppose you are running C: \ Users \ Miyayu \ IDEA \ example \ example.jar. I want to retrieve C: \ Users \ Miyayu \ IDEA \ example (String type).

code

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

only this! Isn't it easy?

If you want to know the absolute path of the specified file

I want to know the absolute path of . \ expdir \ hoge.json

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

Recommended Posts

How to get the absolute path of a directory running in Java
How to get the class name / method name running in Java
[Java] How to get the current directory
How to get the date in java
How to get the length of an audio file in java
[Java] How to get the authority of the folder
[Java] How to get to the front of a specific string using the String class
[Java] How to get the URL of the transition source
[Java] How to get the maximum value of HashMap
How to get the ID of a user authenticated with Firebase in Swift
How to derive the last day of the month in Java
[jsoup] How to get the full amount of a document
How to get the class name of the argument of LoggerFactory.getLogger when using SLF4J in Java
How to save a file with the specified extension under the directory specified in Java to the list
Get the result of POST in Java
How to get the id of PRIMAY KEY auto_incremented in MyBatis
Get the public URL of a private Flickr file in Java
[chown] How to change the owner of a file or directory
[Java] How to convert from String to Path type and get the path
How to check for the contents of a java fixed-length string
How to increment the value of Map in one line in Java
The story of forgetting to close a file in Java and failing
How to display a web page in Java
Measure the size of a folder in Java
How to get Class from Element in Java
How to get today's day of the week
How to get the current date as a string in yyyyMMdd format
How to find out the Java version of a compiled class file
How to find the total number of pages when paging in Java
How to get the value after "_" in Windows batch like Java -version
How to change the value of a variable at a breakpoint in intelliJ
[Java] How to get the redirected final URL
How to create your own annotation in Java and get the value
[Swift] How to get the number of elements in an array (super basic)
graphql-ruby: How to get the name of query or mutation in controller Note
[Rails] How to get rid of flash messages in a certain amount of time
Get the path defined in Controller class of Spring boot as a list
Sample code to get the values of major SQL types in Java + MySQL 8.0
Get the URL of the HTTP redirect destination in Java
How to create a Java environment in just 3 seconds
[Java] How to omit the private constructor in Lombok
How to write Scala from the perspective of Java
[Java] How to extract the file name from the path
Source used to get the redirect source URL in Java
How to create a data URI (base64) in Java
[Java] How to get a request by HTTP communication
[Java] Get the file in the jar regardless of the environment
[Java] Get the file path in the folder with List
[Android] How to get the setting language of the terminal
How to convert A to a and a to A using AND and OR in Java
How to specify the resource path in HTML import
How to convert a file to a byte array in Java
[Rails] How to get the contents of strong parameters
Summary of how to implement default arguments in Java
[Swift] How to get the document ID of Firebase
A memo about the types of Java O/R mappers and how to select them
[Java] How to get the key and value stored in Map by iterative processing
[Java] How to display the day of the week acquired by LocalDate, DateTimeformatter in Japanese
Summary of how to use the proxy set in IE when connecting with Java
An unsupported Java version How to get rid of errors
A quick explanation of the five types of static in Java