Here you can find the source of touch(final File folder, final String fileName)
Parameter | Description |
---|---|
folder | File |
fileName | String |
Parameter | Description |
---|---|
IOException | an exception |
public static void touch(final File folder, final String fileName) throws IOException
//package com.java2s; //License from project: Apache License import java.io.*; public class Main { /**/*from www.ja v a2 s.c o m*/ * Creates a file * * @param folder File * @param fileName String * @throws IOException */ public static void touch(final File folder, final String fileName) throws IOException { if (!folder.exists()) { folder.mkdirs(); } final File touchedFile = new File(folder, fileName); // The JVM will only 'touch' the file if you instantiate a // FileOutputStream instance for the file in question. // You don't actually write any data to the file through // the FileOutputStream. Just instantiate it and close it. FileOutputStream doneFOS = null; try { doneFOS = new FileOutputStream(touchedFile); } catch (FileNotFoundException e) { // Handle error } finally { if (doneFOS != null) { doneFOS.close(); } } } }