更改Java中的当前目录以实现“cd”命令在linux [英] Changing the current directory in Java to implement "cd" command in 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屋!