问题描述
是否可以将Java中的目录下移一个级别?
Is it possible to move to a directory one level down in Java?
例如在命令提示符下:
C:\Users\foo\
我可以使用cd..
转到:
C:\Users\
是否可以在Java
中执行此操作,因为我正在使用System.getProperty("user.dir");获得目录.但是那不是我要使用的目录,而是目录的下一级.
Is it possible to do this in Java
, because I'm getting a directory using System.getProperty("user.dir"); however that is not the directory I'd want to work at, but rather 1 level down the directory.
我已经考虑过使用Path类方法; subpath(i,j)
,但是如果要将"user.dir"更改为另一个目录,则返回的subpath
将有所不同.
I have thought of using the Path class method; subpath(i,j)
, but if the "user.dir" were to be changed to another directory, then the returned subpath
would be different.
推荐答案
File类可以本地执行此操作.
The File class can do this natively.
File upOne = new File(System.getProperty("user.dir")).getParentFile()
http://docs.oracle.com/javase/6/docs/api/java/io/File.html#getParentFile%28%29
这篇关于向下移到上一级目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!