问题描述
我知道。异端。但是我有一个约束我有很多使用绝对路径名的配置文件,这会在OS X和Windows之间造成不兼容。如果我能得到OS X(我敢打赌,这是更灵活的两种)来识别Q:/foo/bar/bim.properties 作为一个有效的绝对文件名,它会保存最后,我需要这些Java测试代码来打印SUCCESS,以便在工作中通过堆栈跟踪和配置文件进行工作。 !当它运行时: import java.io. *;
class DriveLetterTest {
static public main(String ... args){
File f = new File(S:);
if(f.isDirectory()){
System.out.println(SUCCESS!);
} else {
System.out.println(FAIL!);
$ b 任何人都知道这可以是完成了吗?
更新:感谢所有的反馈,每个人。现在很明显,我真的应该在我的问题更清楚。
配置文件和使用它们的代码都属于我无法更改的第三方包。 (好吧,我可以改变它们,但是这意味着需要承担持续的维护工作量,如果可能的话,我想尽量避免这种情况。)
我和你们所有对这种事态感到震惊的人们都表示完全同意。但事实是:我不能改变第三方代码,我真的想避免分配配置文件。
p>最有可能的是你必须提供一个不同的 java.io.File
实现,可以正确解析出文件路径,也许有一个已经创建好的文件。 真正的解决方案是将这种东西(硬编码的文件路径)放在配置文件中,而不是放在源代码中。
I know. Heresy. But I'm in a bind. I have a lot of config files that use absolute path names, which creates an incompatibility between OS X and Windows. If I can get OS X (which I'm betting is the more flexible of the two) to recognize Q:/foo/bar/bim.properties as a valid absolute file name, it'll save me days of work spelunking through stack traces and config files.
In the end, I need this bit of Java test code to print "SUCCESS!" when it runs:
import java.io.*;
class DriveLetterTest {
static public void main(String... args) {
File f = new File("S:");
if (f.isDirectory()) {
System.out.println("SUCCESS!");
} else {
System.out.println("FAIL!");
}
}
}
Anyone know how this can be done?
UPDATE: Thanks for all the feedback, everyone. It's now obvious to me I really should have been clearer in my question.
Both the config files and the code that uses them belong to a third-party package I cannot change. (Well, I can change them, but that means incurring an ongoing maintenance load, which I want to avoid if at all possible.)
I'm in complete agreement with all of you who are appalled by this state of affairs. But the fact remains: I can't change the third-party code, and I really want to avoid forking the config files.
Most likely you'd have to provide a different java.io.File
implementation that can parse out the file paths correctly, maybe there's one someone already made.
The real solution is to put this kind of stuff (hard-coded file paths) in configuration files and not in the source code.
这篇关于我怎样才能让OS X识别驱动器号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!