Here you can find the source of touch(final File file)
public static void touch(final File file) throws IOException
//package com.java2s; // Licensed under the Apache License, Version 2.0 (the "License"); you may import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; public class Main { public static void touch(final String f) throws IOException { touch(new File(f)); }/* ww w . j a v a2 s .co m*/ public static void touch(final File file) throws IOException { if (file.exists()) { if (file.isDirectory()) { throw new IOException("File '" + file + "' exists but is a directory"); } if (file.canWrite() == false) { throw new IOException("File '" + file + "' cannot be written to"); } } else { final File parent = file.getParentFile(); if (parent != null) { if (!parent.mkdirs() && !parent.isDirectory()) { throw new IOException("Directory '" + parent + "' could not be created"); } } final OutputStream out = new FileOutputStream(file); out.close(); } final boolean success = file.setLastModified(System.currentTimeMillis()); if (!success) { throw new IOException("Unable to set the last modification time for " + file); } } }