【发布时间】:2011-04-28 17:52:23
【问题描述】:
我正在寻找一些方法可以让我(在 windows 中)获取保存 windows 的目录(例如在我的 PC 中它将返回“C:\windows”。
我需要它,因为我必须调用这个方法
public static void openFileWithNotepad(String pathFileTxt) throws InterruptedException, IOException
{
if(System.getProperty("os.name").toUpperCase().contains("Windows".toUpperCase()))
{
String program = "C:/WINDOWS/system32/notepad.exe";
Process p = Runtime.getRuntime().exec(program + " " + pathFileTxt);
}
...
}
我想用一些方法来切换“C:/WINDOWS”和操作系统安装文件夹,以便在不同的电脑上使用这个程序。
P.S.:如果有人知道,我也想知道如何在 UNIX 操作系统上使用此方法:)
感谢您的理解!
【问题讨论】:
-
你为什么不直接运行
notepad.exe让系统从它的路径中找到它? -
除了假设记事本是默认编辑器,您还可以这样做:
Runtime.getRuntime().exec("cmd /c start myfile.txt");,它将在用户的默认编辑器中打开文本文件。