更改Java中的当前目录以实现“cd”命令在linux中 [英] Changing the current directory in Java to implement "cd" command in linux

查看:319
本文介绍了更改Java中的当前目录以实现“cd”命令在linux中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个在linux中实现cd命令的命令行解释器。我不知道这个功能如何做这个工作。

I'm trying to build a command line interpreter that implements "cd" command in linux. I don't know how the function that suppose to do that shoud work.

我知道这个问题已经在这里回答:
更改Java中的当前工作目录

I know that this question has already been answered here: Changing the current working directory in Java?

但我是Java的新手,我读了很多关于这一点,仍然没有得到如何新的文件(父,路径)将帮助我更改我的目录。任何帮助?

But I'm new to Java and I read alot about this and still don't get how new File(parent, path) would help me change my directory. Any help please?

推荐答案

我使用了一个保存我当前方向路径的全局变量。 cd 只会更改它,所有其他命令会相应地使用/修改它。没有什么比我更简单的。

I used a global variable that holds the path of my current direction. cd would just change it and all other commands use/modify it accordingly. Nothing simpler I guess.

这篇关于更改Java中的当前目录以实现“cd”命令在linux中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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