Here you can find the source of createFileWithContents(String pathString, String contents)
static public Path createFileWithContents(String pathString, String contents) throws IOException
//package com.java2s; /******************************************************************************* * SiniaUtils/*from w ww.j a v a2s . com*/ * Copyright (c) 2011-2 Siniatech Ltd * http://www.siniatech.com/products/siniautils * * All rights reserved. This project and the accompanying materials are made * available under the terms of the MIT License which can be found in the root * of the project, and at http://www.opensource.org/licenses/mit-license.php * ******************************************************************************/ import static java.nio.file.Files.*; import java.io.BufferedWriter; import java.io.IOException; import java.nio.charset.Charset; import java.nio.file.FileSystems; import java.nio.file.Path; public class Main { static public Path createFileWithContents(String pathString, String contents) throws IOException { Path path = FileSystems.getDefault().getPath(pathString); if (exists(path)) { throw new IOException("File " + pathString + " already exists."); } else { createFile(path); } try (BufferedWriter out = newBufferedWriter(path, Charset.defaultCharset())) { out.write(contents); return path; } } }