8. How do you create a file and directory in Java code example
Example 1: java create file in folder
File file = new File("src/resources/run.txt");
file.getParentFile().mkdirs();
FileWriter writer = new FileWriter(file);
writer.append("this is a test");
writer.close();
Example 2: java create file in folder
File file = new File("src/resources/run.txt");
file.getParentFile().mkdirs();
file.createNewFile();