我已经创建了一个Java程序来创建一个以文件名作为用户输入的C ++文件,然后在文件创建完成后,该程序应在CodeBlocks中自动打开创建的C ++文件。
System.out.println("Enter the Name of the file to be created ---");
name =sc.next();
File f = new File(name+".cpp");
if(f.exists())
{
System.out.println("File already exists");
}
else
{
try{
f.createNewFile();
FileWriter fw = new FileWriter(name+".cpp");
fw.write("#include<bits/stdc++.h>\r\nusing namespace std;\r\nint main()\r\n{\r\n"
+ "ios_base::sync_with_stdio(false);\r\ncin.tie(NULL);\r\n\r\nreturn 0;\r\n}");
fw.close();
}
catch(Exception e){System.out.println(e);}
System.out.println("!! File Sucessfully Created !!");
try {
Runtime r = Runtime.getRuntime();
r.exec("CodeBlocks C:\\Users\\ADITYA\\Documents\\codeblocks progs\\"+name+".cpp");
} catch (IOException e) {
System.out.println(e.printStackTrace());
}
}
答案 0 :(得分:0)
类似
Process p = Runtime.getRuntime().exec("path/to/codeblock/executable --file="+filePath);