|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.esa.beam.util.io.FileUtils
public class FileUtils
This class provides additional functionality in handling with files. All methods in this class dealing with extensions, expect that an extension is the last part of a file name starting with the dot '.' character.
| Constructor Summary | |
|---|---|
FileUtils()
|
|
| Method Summary | |
|---|---|
static FilenameFilter |
createExtensionFilenameFilter(String extension)
Creates a file filter which only lets files through which have the given extension. |
static String |
createValidFilename(String name)
Creates a valid filename for the given source name. |
static boolean |
deleteTree(File tree)
Recursively deletes the directory tree. |
static File |
ensureExtension(File file,
String extension)
Returns a file with the given extension. |
static String |
ensureExtension(String path,
String extension)
Returns a file with the given extension. |
static File |
exchangeExtension(File file,
String extension)
Returns a file with the given new extension. |
static String |
exchangeExtension(String path,
String extension)
Returns the file string with the given new extension. |
static String |
getDisplayText(File file,
int maxLength)
|
static String |
getExtension(File file)
Gets the extension (which always includes a leading dot) of a file. |
static String |
getExtension(String path)
Gets the extension of a file path. |
static int |
getExtensionDotPos(String path)
|
static URL |
getFileAsUrl(File file)
Gets a normalized URL representation for the given file. |
static String |
getFileNameFromPath(String path)
Retrieves the file name from a complete path. |
static String |
getFilenameWithoutExtension(File file)
Gets the filename without its extension from the given file path. |
static String |
getFilenameWithoutExtension(String fileName)
Gets the filename without its extension from the given filename. |
static File |
getUrlAsFile(URL url)
Inverse of getFileAsUrl(java.io.File). |
static String[] |
listFilePathsWithExtension(File dir,
String extension)
Lists the filenames with the specified extension contained in the given directory. |
static File[] |
listFilesWithExtension(File dir,
String extension)
Lists the files with the specified extension contained in the given directory. |
static String |
readText(File file)
|
static String |
readText(Reader reader)
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public FileUtils()
| Method Detail |
|---|
public static String getExtension(File file)
file - the file whose extension is to be extracted.
null if the file has
no extension.public static String getExtension(String path)
path - the file path whose extension is to be extracted.
null if the file path has
no extension.public static String getFilenameWithoutExtension(File file)
file - the file whose filename is to be extracted.
public static String getFilenameWithoutExtension(String fileName)
fileName - the name of the file whose filename is to be extracted.
public static String exchangeExtension(String path,
String extension)
"tie.point.grids\tpg1.hdr"results to
"tie.point.grids\tpg1.raw"Example2:
"tie.point.grids\tpg1"results to
"tie.point.grids\tpg1.raw"
path - the string to change the extensionextension - the new file extension including a leading dot (e.g. ".raw").
IllegalArgumentException - if one of the given strings are null or empty.
public static File exchangeExtension(File file,
String extension)
"tie.point.grids\tpg1.hdr"results to
"tie.point.grids\tpg1.raw"Example2:
"tie.point.grids\tpg1"results to
"tie.point.grids\tpg1.raw"
file - the file to change the extensionextension - the new file extension including a leading dot (e.g. ".raw").
IllegalArgumentException - if one of the parameter strings are null or empty.
public static String ensureExtension(String path,
String extension)
"example.dim"results to
"example.dim"Example2: param path = example param extension = ".dim"
"example"results to
"example.dim"Example3: param path = example.lem param extension = ".dim"
"example.lem"results to
"example.lem.dim"
path - the string to ensure the extensionextension - the new file extension including a leading dot (e.g. ".raw").
IllegalArgumentException - if one of the given strings are null or empty.
public static File ensureExtension(File file,
String extension)
"example.dim"results to
"example.dim"Example2: param file = example param extension = ".dim"
"example"results to
"example.dim"Example3: param file = example.lem param extension = ".dim"
"example.lem"results to
"example.lem.dim"
file - the file to ensure the extensionextension - the new file extension including a leading dot (e.g. ".raw").
IllegalArgumentException - if one of the parameter strings are null or empty.public static int getExtensionDotPos(String path)
public static String getFileNameFromPath(String path)
public static File[] listFilesWithExtension(File dir,
String extension)
File.listFiles(),
File.listFiles(java.io.FilenameFilter)
public static String[] listFilePathsWithExtension(File dir,
String extension)
File.list(),
File.list(java.io.FilenameFilter)public static FilenameFilter createExtensionFilenameFilter(String extension)
FilenameFilterpublic static String createValidFilename(String name)
name - the source name, must not be null
public static URL getFileAsUrl(File file)
throws MalformedURLException
Unlike the File.toURL() method,
this method automatically escapes characters that are illegal in URLs.
It converts the given abstract pathname into a URL by first converting it into a
URI, via the File.toURI() method, and then converting the URI
into a URL via the URI.toURL method.
.
See also the 'Usage Note' of the File.toURL() API documentation.
file - the file
MalformedURLException
public static File getUrlAsFile(URL url)
throws URISyntaxException
getFileAsUrl(java.io.File).
url - the URL
URISyntaxException
public static String getDisplayText(File file,
int maxLength)
public static String readText(File file)
throws IOException
IOException
public static String readText(Reader reader)
throws IOException
IOExceptionpublic static boolean deleteTree(File tree)
tree.
tree - directory to be deleted
true if and only if the file or directory is
successfully deleted; false otherwise
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||