jlibs.core.io
Class FileUtil

java.lang.Object
  extended by jlibs.core.io.FileUtil

public class FileUtil
extends Object

Author:
Santhosh Kumar T

Nested Class Summary
static interface FileUtil.FileCreator
           
 
Field Summary
static File JAVA_HOME
           
static String LINE_SEPARATOR
           
static String PATH_SEPARATOR
           
static String SEPARATOR
           
static File TMP_DIR
           
static File USER_DIR
           
static File USER_HOME
           
 
Constructor Summary
FileUtil()
           
 
Method Summary
static void copy(File source, File target)
           
static void copy(File source, File target, FileUtil.FileCreator creator)
           
static void copyInto(File source, File targetDir)
           
static void copyInto(File source, File targetDir, FileUtil.FileCreator creator)
           
static void delete(File file)
          deletes specified file or directory if given file/dir doesn't exist, simply returns
static void deleteEmptyDirs(File directory)
           
static File findFreeFile(File file)
          if file doesn't exist, it returns the same file.
static File findFreeFile(File dir, String pattern, boolean tryEmptyVar)
          Finds a free file (i.e non-existing) in specified directory, using specified pattern.
static String getExtension(String fileName)
          Returns extension of the file.
static String getName(String fileName)
          Returns name of the file without extension
static void main(String[] args)
           
static void mkdir(File dir)
          create specified directory if doesn't exist.
static void mkdirs(File dir)
          create specified directory if doesn't exist.
static String[] split(String fileName)
          splits given fileName into name and extension.
static URL toURL(File file)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PATH_SEPARATOR

public static final String PATH_SEPARATOR

SEPARATOR

public static final String SEPARATOR

LINE_SEPARATOR

public static final String LINE_SEPARATOR

JAVA_HOME

public static final File JAVA_HOME

USER_HOME

public static final File USER_HOME

USER_DIR

public static final File USER_DIR

TMP_DIR

public static final File TMP_DIR
Constructor Detail

FileUtil

public FileUtil()
Method Detail

toURL

public static URL toURL(File file)

split

public static String[] split(String fileName)
splits given fileName into name and extension.

Parameters:
fileName - fileName
Returns:
string array is of length 2, where 1st item is name and 2nd item is extension(null if no extension)

getName

public static String getName(String fileName)
Returns name of the file without extension


getExtension

public static String getExtension(String fileName)
Returns extension of the file. Returns null if there is no extension


findFreeFile

public static File findFreeFile(File dir,
                                String pattern,
                                boolean tryEmptyVar)
Finds a free file (i.e non-existing) in specified directory, using specified pattern. for example: findFreeFile(myDir, "sample${i}.xml", false) will search for free file in order: sample1.xml, sample2.xml, sample3.xml and so on if tryEmptyVar is true, it it seaches for free file in order: sample.xml, sample2.xml, sample3.xml and so on the given pattern must have variable part ${i}


findFreeFile

public static File findFreeFile(File file)
if file doesn't exist, it returns the same file. otherwize, it will find free file as follows: if given file name is test.txt, then it searches for non existing file in order: test2.txt, test3.txt, test4.txt and so on if given file name is test(i,e with no extension), then it searches for non existing file in order: test2, test3, test4 and so on


delete

public static void delete(File file)
                   throws IOException
deletes specified file or directory if given file/dir doesn't exist, simply returns

Throws:
IOException

deleteEmptyDirs

public static void deleteEmptyDirs(File directory)
                            throws IOException
Throws:
IOException

mkdir

public static void mkdir(File dir)
                  throws IOException
create specified directory if doesn't exist.

Throws:
IOException

mkdirs

public static void mkdirs(File dir)
                   throws IOException
create specified directory if doesn't exist. if any parent diretories doesn't exist they will be created implicitly

Throws:
IOException

copyInto

public static void copyInto(File source,
                            File targetDir)
                     throws IOException
Throws:
IOException

copy

public static void copy(File source,
                        File target)
                 throws IOException
Throws:
IOException

copyInto

public static void copyInto(File source,
                            File targetDir,
                            FileUtil.FileCreator creator)
                     throws IOException
Throws:
IOException

copy

public static void copy(File source,
                        File target,
                        FileUtil.FileCreator creator)
                 throws IOException
Throws:
IOException

main

public static void main(String[] args)
                 throws IOException
Throws:
IOException


Copyright © 2018. All rights reserved.