向下移到上一级目录 [英] Moving to a directory one level down

查看:92
本文介绍了向下移到上一级目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将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

这篇关于向下移到上一级目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆