java中关于Runtime.getRuntime().exec()的问题
Stringstring=newfile.getPath();string=string.replace("\\","\\\\");try{Processp=Runtim...
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();
} 展开
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();
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询