com.marringtons.file
Class Files

java.lang.Object
  extended bycom.marringtons.file.Files

public class Files
extends Object

Static file helper methods for finding, reading and unlinking files.

Author:
Paul Marrington

Method Summary
static String find(String fileName)
          Look for an existing file or directory on the data paths and return it's absolute path.
static File findFile(String fileName)
          Look for an existing file or directory on the data paths and return it's File Object.
static String getName(File file)
          Given a File object return it's absolute path.
static String getType(String name)
          Get the file type by file extension.
static String[] readLines(InputStream stream)
          Read all the data in a file and return as an array of lines.
static boolean unlink(String name)
          Delete a file (can be on the path).
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getType

public static String getType(String name)
Get the file type by file extension.

Parameters:
name - file name and path to check;
Returns:
type of file (txt, gif, etc) in lower case (empty if no type found)

readLines

public static String[] readLines(InputStream stream)
                          throws IOException
Read all the data in a file and return as an array of lines.

Parameters:
stream - to break into lines.
Returns:
the complete file stream as an array of lines
Throws:
IOException

findFile

public static File findFile(String fileName)
Look for an existing file or directory on the data paths and return it's File Object.

Parameters:
fileName - name of file to find
Returns:
File object or null if not found

find

public static String find(String fileName)
Look for an existing file or directory on the data paths and return it's absolute path.

Parameters:
fileName - name of file to find.
Returns:
Absolute normalised path to file, or null if file does not exist.

getName

public static String getName(File file)
Given a File object return it's absolute path.

Parameters:
file - File object instance.
Returns:
Absolute normalised path to file - null if file does not exist

unlink

public static boolean unlink(String name)
Delete a file (can be on the path).

Parameters:
name - of file to delete.
Returns:
true if file deleted, false if delete failed or file does not exist.


Copyright © 2005 Paul Marrington http://library.marringtons.com