0
The file, in fact, is created, but without the content it should have.
Method Program
:
String program() {
return "import java.io.*;\n"
+ "import javax.swing.JOptionPane;\n"
+ "\n"
+ "public class Main {\n"
+ " \n"
+ " static final Runtime run = Runtime.getRuntime();\n"
+ " static Process pro;\n"
+ " static BufferedReader read;\n"
+ "\n"
+ " public static void main(String[] args) {\n"
+ " String[] cmds = {\n"
+ " \"cd /d D:\\\\Desenvolvimento\\\\snippets-codes && concurrently \\\"cd snippets && serve\\\" \\\"cd backend && adonis serve --dev\\\"\",\n"
+ " };\n"
+ "\n"
+ " try {\n"
+ " ProcessBuilder builder = new ProcessBuilder(\"cmd\", \"/c\",\n"
+ " String.join(\"& \", cmds));\n"
+ "\n"
+ " builder.redirectErrorStream(true);\n"
+ "\n"
+ " Process p = builder.start();\n"
+ "\n"
+ " BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));\n"
+ " String line;\n"
+ "\n"
+ " while (true) {\n"
+ " line = r.readLine();\n"
+ " if (line == null) {\n"
+ " break;\n"
+ " }\n"
+ "\n"
+ " System.out.println(line);\n"
+ " }\n"
+ " } catch (Exception e) {\n"
+ " JOptionPane.showMessageDialog(null, e.getMessage(), \"Atenção\", 1);\n"
+ " }\n"
+ " }\n"
+ "}";
}
Code to create the file and insert some content into it:
try {
PrintWriter writer = new PrintWriter("C:\\Users\\MY_USER_NAME\\Desktop\\teste.java", "UTF-8");
String[] words = program().split("\\n");
for (String word : words) {
System.out.println(word);
writer.println(word);
}
} catch (FileNotFoundException | UnsupportedEncodingException ex) {
JOptionPane.showMessageDialog(null, ex.getMessage(), "Atenção", 1);
}
Thanks, it worked out.
– Taffarel Xavier