Java File Touch touchFile(File directory, String name)

Here you can find the source of touchFile(File directory, String name)

Description

touch File

License

Open Source License

Declaration

public static File touchFile(File directory, String name) throws FileNotFoundException 

Method Source Code

//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);
        }
    }
}

Related

  1. touch(String filePath)
  2. touch(String fullFilePath)
  3. touch(String name)
  4. touchDir(String filePath)
  5. touchExisting(File file)
  6. touchFile(File file)
  7. touchFile(File file)
  8. touchFile(String target)
  9. touchOrCrash(File f)