Package net.sf.statcvs.util
Class FileUtils
- java.lang.Object
-
- net.sf.statcvs.util.FileUtils
-
public class FileUtils extends java.lang.Object
Some helpful file functions TODO: Remove redundancy, write tests- Version:
- $Id: FileUtils.java,v 1.21 2009/08/19 22:11:15 benoitx Exp $
- Author:
- Lukasz Pekacki
-
-
Constructor Summary
Constructors Constructor Description FileUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
copyFile(java.io.InputStream in, java.io.File out)
Copy a InputStream into a Filestatic void
copyFile(java.lang.String inputName, java.lang.String destination)
Copies a file to a specified destinationstatic java.lang.String
getAbsoluteName(java.lang.String path, java.lang.String filename)
Concatenatespath
and filename to an absolute filename by inserting the system file separator.static java.lang.String
getDefaultDirSeparator()
Returns the java path separatorstatic java.lang.String
getDirectoryName(java.lang.String path)
Returns the last component of a directory path.static java.lang.String
getDirSeparator()
Returns the os dependent path separatorstatic java.lang.String
getFilenameWithoutPath(java.lang.String filename)
Takes a filename with path and returns just the filename.static java.lang.String
getParentDirectoryPath(java.lang.String path)
Returns all but the last component of a directory pathstatic java.lang.String
getPathWithoutEndingSlash(java.lang.String path)
Deletes the ending directory separator of a givenpath
if there is one and returns the result.static java.lang.String
readTextFromURL(java.lang.String urlTxt)
Read a full file into a string.
-
-
-
Method Detail
-
copyFile
public static void copyFile(java.lang.String inputName, java.lang.String destination) throws java.io.FileNotFoundException, java.io.IOException
Copies a file to a specified destination- Parameters:
inputName
- Filedestination
- Filename- Throws:
java.io.FileNotFoundException
- if no input file existsjava.io.IOException
- if cannot read or write
-
copyFile
public static void copyFile(java.io.InputStream in, java.io.File out) throws java.io.FileNotFoundException, java.io.IOException
Copy a InputStream into a File- Parameters:
in
- sourceout
- destination- Throws:
java.io.FileNotFoundException
- if not foundjava.io.IOException
- if read/write error
-
getFilenameWithoutPath
public static java.lang.String getFilenameWithoutPath(java.lang.String filename)
Takes a filename with path and returns just the filename.- Parameters:
filename
- a filename with path- Returns:
- just the filename part
-
getDirSeparator
public static java.lang.String getDirSeparator()
Returns the os dependent path separator- Returns:
- String os dependent path separator
-
getDefaultDirSeparator
public static java.lang.String getDefaultDirSeparator()
Returns the java path separator- Returns:
- String java path separator
-
getPathWithoutEndingSlash
public static java.lang.String getPathWithoutEndingSlash(java.lang.String path)
Deletes the ending directory separator of a givenpath
if there is one and returns the result. Otherwise the path is unhandled returned.The separator is the one used bye the underlying operating system and it is the one returned bye the
getDirSeparator()
method.- Parameters:
path
- Thepath
to delete the directory separator from.- Returns:
- The
path
without the ending directory separator. - See Also:
getDirSeparator()
-
getAbsoluteName
public static java.lang.String getAbsoluteName(java.lang.String path, java.lang.String filename)
Concatenatespath
and filename to an absolute filename by inserting the system file separator.- Parameters:
path
- The path to use.filename
- The filename for concatenation.- Returns:
- The concatenated absolute filename.
-
getDirectoryName
public static java.lang.String getDirectoryName(java.lang.String path)
Returns the last component of a directory path.- Parameters:
path
- a directory, ending in "/", for example "src/net/sf/statcvs/"- Returns:
- the last component of the path, for example "statcvs"
-
getParentDirectoryPath
public static java.lang.String getParentDirectoryPath(java.lang.String path)
Returns all but the last component of a directory path- Parameters:
path
- a directory, ending in "/", for example "src/net/sf/statcvs/"- Returns:
- all but the last component of the path, for example "src/net/sf/"
-
readTextFromURL
public static java.lang.String readTextFromURL(java.lang.String urlTxt)
Read a full file into a string.- Parameters:
urlTxt
- URL of the text to get- Returns:
-
-