Java 8 style
Path path = Paths.get("logs/error.log"); Files.createDirectories(path.getParent());
Write to file
Files.write(path, "Log log".getBytes());
To read
System.out.println(Files.readAllLines(path));
Full example
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(); } } }
ahmet May 31 '18 at 8:40 2018-05-31 08:40
source share