Стиль Java 8
Path path = Paths.get("logs/error.log");
Files.createDirectories(path.getParent());
Щоб писати у файл
Files.write(path, "Log log".getBytes());
Читати
System.out.println(Files.readAllLines(path));
Повний приклад
public class CreateFolderAndWrite {
public static void main(String[] args) {
try {
Path path = Paths.get("logs/error.log");
Files.createDirectories(path.getParent());
Files.write(path, "Log log".getBytes());
System.out.println(Files.readAllLines(path));
} catch (IOException e) {
e.printStackTrace();
}
}
}