Here you can find the source of touchFile(File directory, String name)
public static File touchFile(File directory, String name) throws FileNotFoundException
//package com.java2s; /*// www. j a va 2s . c o m Copyright 2012 Daniel Gonzalez Pe?a, Osvaldo Gra?a This file is part of the bicycle Project. bicycle Project is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. bicycle Project is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser Public License for more details. You should have received a copy of the GNU Lesser Public License along with bicycle Project. If not, see <http://www.gnu.org/licenses/>. */ import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; public class Main { public static File touchFile(File directory, String name) throws FileNotFoundException { File newfile = new File(directory.getAbsolutePath() + File.separator + name); touchFile(newfile); return newfile; } public static void touchFile(File f) throws FileNotFoundException { if (!f.exists()) { new FileOutputStream(f); } } }