Here you can find the source of saveToFile(String content, String directoryPath, String filename)
public static void saveToFile(String content, String directoryPath, String filename)
//package com.java2s; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; public class Main { public static void saveToFile(String content, String directoryPath, String filename) { createDirIfDoesNotExist(directoryPath); try {/*from w ww . j a va 2 s . c o m*/ Files.write(Paths.get(directoryPath + filename), content.getBytes()); } catch (IOException e) { e.printStackTrace(); } } public static void createDirIfDoesNotExist(String websitesDirPath) { Path directoryPath = Paths.get(websitesDirPath); if (!Files.exists(directoryPath)) { try { Files.createDirectory(directoryPath); } catch (IOException e) { e.printStackTrace(); } } } }