String string = newfile.getPath();
string = string.replace("\\", "\\\\");
try {
Process p = Runtime.getRuntime().exec( "C:\\WINDOWS\\system32\\notepad.exe " + string);
} catch (IOException e1) {
e1.printStackTrace();
}
问题:为什么每次都同时打开这个文件两次那?哪里出了问题?谢谢。。。
if (e.getSource() == Translate)
{
File newfile = new File("d:\\modelchecking\\" + ModelNameF.getText()+ ".pml");
String string1 = "", string2 = "", string21 = "", string3 = "", string4 = "", string5 = ""
try{
if (!newfile.exists()) {
newfile.createNewFile();
//给几个字符串赋值;}
else System.out.println(ModelNameF.getText() + ".txt文件已经存在!");
}catch (Exception err) {
System.err.println("文件创建发生异常");
err.printStackTrace(); }
writeFile(newfile, string1 + string21 + string2 + string3 + string4+ string5);
// 用记事本打开文件
String temps = newfile.getPath();
temps = temps.replace("\\", "\\\\");
try { Process p = Runtime.getRuntime().exec(
"C:\\WINDOWS\\system32\\notepad.exe " + temps);
} catch (IOException e1) {
e1.printStackTrace(); }
jf.dispose();
}
java中关于Runtime.getRuntime().exec()的问题
答案:2 悬赏:0
解决时间 2021-04-07 20:12
- 提问者网友:很好的背叛
- 2021-04-07 01:23
最佳答案
- 二级知识专家网友:万千宠爱
- 2021-04-07 02:31
是不是你调用了2次啊,外部还有没有循环?
这个JDK 1.5下面测试只会打开一个文件的,
贴完整代码上来
这个JDK 1.5下面测试只会打开一个文件的,
贴完整代码上来
全部回答
- 1楼网友:社会水太深
- 2021-04-07 02:55
用这个有时就是会出现毛病。可能还得再加些参数。
你用desktop类。
打开一个文件
desktop d=desktop.getdesktop();
d.open("d:\\games\\打砖块\\dxball2.exe");
这个方法肯定可以打开。它是利用windows的默认打开方式的
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯