简体   繁体   English

为什么chdir在Java中不支持?

[英]Why chdir does not support in java?

我想知道Java为什么不提供chdir调用实现,却提供相同的本机接口的真正原因。

The full evaluation can be found in Sun/Oracle's bug database with issue number JDK-4045688 : Add chdir or equivalent notion of changing working directory 完整的评估可以在Sun / Oracle的错误数据库中找到,版本号JDK-4045688:添加chdir或等效的更改工作目录的概念

It was decided to close the ticket because there are major issues with any solution, and none of the customers that reported the bug really needed it - all of them were able to use a workaround. 由于任何解决方案都存在重大问题,并且没有任何报告该错误的客户真正需要它,因此决定关闭故障单-他们所有人都可以使用解决方法。

One excerpt from the bug database that highlights the issues with adding such a call: 错误数据库的摘录突出显示了添加此类调用的问题:

EVALUATION 评估

This feature can be interpreted in two ways: chdir could change the current working directory of the process containing the JVM, causing all threads to change simultaneously, or to provide a more "virtual" per-thread concept of current directory, which could conceptually be a ThreadLocal. 可以通过两种方式来解释此功能:chdir可以更改包含JVM的进程的当前工作目录,从而导致所有线程同时更改,或者提供当前目录的更“虚拟”的每线程概念,从概念上讲可以ThreadLocal。 This would be merely a convenience for building up complete path names to pass to the underlying operating system API. 这只是建立完整路径名以传递给底层操作系统API的一种方便。

This is how the current directory works in Emacs - it's just a variable, but a magic one that can have buffer-local values. 这就是当前目录在Emacs中的工作方式-它只是一个变量,但是可以包含局部缓冲区值的神奇目录。 Emacs buffers are kinda sorta like Java threads in this sense. 从这个意义上讲,Emacs缓冲区有点像Java线程。 Such an implementation would offer convenience and safety. 这样的实现将提供便利和安全。 Having each thread with a ThreadLocal current directory gives a programmer experience familiar to old Unix greybeards, except that Threads replace Processes. 每个线程都具有ThreadLocal当前目录,这为程序员带来了与旧Unix灰胡子熟悉的经验,只是线程代替了进程。

Many workarounds are also described there, such as executing a subprocess with a new current directory, or always qualifying your file accesses with the parent directory from where you want your relative part to start. 此处还描述了许多解决方法,例如使用新的当前目录执行子过程,或始终使用希望您的相对部分开始的父目录来限定文件访问权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM