java - 如何使用 Java 程序在 CodeBlocks 中打开特定的 C++ 文件?
问题描述
我创建了一个 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());
}
}
解决方案
推荐阅读
- angular - firebase auth/unauthorized-domain 错误,虽然我授权了域
- scala - 如何在scala中将函数的输出结果作为PUT请求提供?
- python - 在机器人关键字中实现增量数值变量
- .net - Docket.DotNet 的 Docker 桌面问题,第二次调用 _dockerClient.Containers.StartContainerAsync() 将失败并出现 OperationCanceledException
- nfc - 读取数据 ST25DV
- javascript - 无法从 NY Times API 检索数据
- kubernetes - Kubernetes - 重启后指标不显示
- git - 将 git 远程部分同步到另一个
- node.js - 无法安装 expo-cli --global
- c# - Task.Run 出现异步方法错误