I have created a Java program to create a C++ file taking the file name as the user input and then after the file creation is done, the program should automatically open the created C++ file in CodeBlocks.
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());
}
}