Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
140 views
in Technique[技术] by (71.8m points)

java - I want to use parent directory‘s parent directory

I am making a Java program and I want use parent directory’s parent directory, as I want to change the content of a file which is in that directory.

So far I tried :

static File pdir = new File(System.getProperty("user.dir")).getParentFile();
static File pdir2 = new File(System.getProperty("pdir")).getParentFile();

and some other things like that but none of them worked.

Error, on the second line, was:

Exception in thread "main" java.lang.ExceptionInInitializerError at Plugin.main.main(main.java:20) Caused by: java.lang.NullPointerException at java.base/java.io.File.(File.java:278) at Plugin.pfun.(pfun.java:13) ... 1 more

Can you recommend anything?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Change the second line to

static File pdir2 = pdir.getParentFile();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...