util
Class InputOutput

java.lang.Object
  extended by util.InputOutput

public final class InputOutput
extends Object

Helper methods related to the filesystem, but not included in java.nio or java.io


Field Summary
static String FILE_SEPARATOR
          File separator, OS-dependent
static String LINE_SEPARATOR
          Line separator, OS-dependent
 
Constructor Summary
InputOutput()
           
 
Method Summary
static Collection<String> getFilePathsEndingWith(String directory, String suffix)
          Returns a list containing the absolute path of every file that is contained in the given directory and has the given suffix
static Collection<String> getFilePathsMatching(String directory, String suffix)
          Returns a list containing the absolute path of every file that is contained in the given directory and matches the given regular expression.
static Collection<String> getFilePathsStartingWith(String directory, String prefix)
          Returns a list containing the absolute path of every file that is contained in the given directory and has the given prefix
static void write(String filePath, String text)
          Appends the given text into the designated file
static void write(String filePath, String text, boolean append)
          Write the given text into the designated file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FILE_SEPARATOR

public static final String FILE_SEPARATOR
File separator, OS-dependent


LINE_SEPARATOR

public static final String LINE_SEPARATOR
Line separator, OS-dependent

Constructor Detail

InputOutput

public InputOutput()
Method Detail

getFilePathsMatching

public static Collection<String> getFilePathsMatching(String directory,
                                                      String suffix)
Returns a list containing the absolute path of every file that is contained in the given directory and matches the given regular expression.

Parameters:
directory - absolute path representing a directory
suffix - regular expression
Returns:
full paths of all files matching the given criteria

getFilePathsEndingWith

public static Collection<String> getFilePathsEndingWith(String directory,
                                                        String suffix)
Returns a list containing the absolute path of every file that is contained in the given directory and has the given suffix

Parameters:
directory - absolute path representing a directory.
suffix - suffix we are looking for.
Returns:
full paths of all files matching the given criteria.

getFilePathsStartingWith

public static Collection<String> getFilePathsStartingWith(String directory,
                                                          String prefix)
Returns a list containing the absolute path of every file that is contained in the given directory and has the given prefix

Parameters:
directory - absolute path representing a directory
prefix - prefix we are looking for
Returns:
full paths of all files matching the given criteria

write

public static void write(String filePath,
                         String text)
                  throws IOException
Appends the given text into the designated file

Parameters:
filePath - full path to a file; if the file does not exist, it is created.
text - text to write in the file
Throws:
IOException - if there is an error while writing or closing the file

write

public static void write(String filePath,
                         String text,
                         boolean append)
                  throws IOException
Write the given text into the designated file.

Parameters:
filePath - full path to a file; if the file does not exist, it is created.
text - text to write in the file
append - whether to append (true) to or overwrite (false) the contents of the file
Throws:
IOException - if there is an error while writing or closing the file