net.i2p.util
Class FileUtil

java.lang.Object
  extended by net.i2p.util.FileUtil

public class FileUtil
extends java.lang.Object

General helper methods for messing with files


Constructor Summary
FileUtil()
           
 
Method Summary
static boolean copy(java.lang.String source, java.lang.String dest, boolean overwriteExisting)
          return true if it was copied successfully
static boolean extractZip(java.io.File zipfile, java.io.File targetDir)
           
static void main(java.lang.String[] args)
          Usage: FileUtil (delete path | copy source dest)
static void readFile(java.lang.String path, java.lang.String root, java.io.OutputStream out)
          Dump the contents of the given path (relative to the root) to the output stream.
static java.lang.String readTextFile(java.lang.String filename, int maxNumLines, boolean startAtBeginning)
          Read in the last few lines of a (newline delimited) textfile, or null if the file doesn't exist.
static boolean rmdir(java.io.File target, boolean failIfNotEmpty)
          Delete the path as well as any files or directories underneath it.
static boolean rmdir(java.lang.String path, boolean failIfNotEmpty)
          Delete the path as well as any files or directories underneath it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileUtil

public FileUtil()
Method Detail

rmdir

public static final boolean rmdir(java.lang.String path,
                                  boolean failIfNotEmpty)
Delete the path as well as any files or directories underneath it.

Parameters:
path - path to the directory being deleted
failIfNotEmpty - if true, do not delete anything if the directory is not empty (and return false)
Returns:
true if the path no longer exists (aka was removed), false if it remains

rmdir

public static final boolean rmdir(java.io.File target,
                                  boolean failIfNotEmpty)
Delete the path as well as any files or directories underneath it.

Parameters:
target - the file or directory being deleted
failIfNotEmpty - if true, do not delete anything if the directory is not empty (and return false)
Returns:
true if the path no longer exists (aka was removed), false if it remains

extractZip

public static boolean extractZip(java.io.File zipfile,
                                 java.io.File targetDir)

readTextFile

public static java.lang.String readTextFile(java.lang.String filename,
                                            int maxNumLines,
                                            boolean startAtBeginning)
Read in the last few lines of a (newline delimited) textfile, or null if the file doesn't exist.

Parameters:
startAtBeginning - if true, read the first maxNumLines, otherwise read the last maxNumLines
maxNumLines - max number of lines (or -1 for unlimited)

readFile

public static void readFile(java.lang.String path,
                            java.lang.String root,
                            java.io.OutputStream out)
                     throws java.io.IOException
Dump the contents of the given path (relative to the root) to the output stream. The path must not go above the root, either - if it does, it will throw a FileNotFoundException

Throws:
java.io.IOException

copy

public static boolean copy(java.lang.String source,
                           java.lang.String dest,
                           boolean overwriteExisting)
return true if it was copied successfully


main

public static void main(java.lang.String[] args)
Usage: FileUtil (delete path | copy source dest)