简体   繁体   中英

Get parent directory of CWD in Java

I am using System.getProperty("user.dir") to get my CWD. I then trim off the last \\token to give me the parent directory.

My question is , is there any easier way to do it? I want the current working directory, cd up one level and then drill into a sub folder in another project.

I run my unit tests in \\\\projectA\\test but I want to get the path to another folder contained in a project at the same level. ie folder \\\\projectB\\otherTestData

Check getparent and getParentFile methods in File class.

For more details see here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM