public class FileUtil
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static byte[] |
BOM_UTF16BE
Byte order mark for UTF-16 big-endian
|
static byte[] |
BOM_UTF16LE
Byte order mark for UTF-16 little-endian
|
static byte[] |
BOM_UTF32BE
Byte order mark for UTF-32 big-endian
|
static byte[] |
BOM_UTF32LE
Byte order mark for UTF-32 little-endian
|
static byte[] |
BOM_UTF8
Byte order mark for UTF-8
|
static java.lang.String |
FILE_TYPE_CHECKLIST
Checklist file extension
|
static java.lang.String |
FILE_TYPE_CONFIG
Config file extension (not used often)
|
static java.lang.String |
FILE_TYPE_CONSOLE
Console file extension
|
static java.lang.String |
FILE_TYPE_INI
INI file extension
|
static java.lang.String |
FILE_TYPE_LSF
LSF (LSTS Serialized Format) file extension
|
static java.lang.String |
FILE_TYPE_LSF_COMPRESSED
GZipped compressed LSF (LSTS Serialized Format) file extension
|
static java.lang.String |
FILE_TYPE_LSF_COMPRESSED_BZIP2
BZipped2 compressed LSF (LSTS Serialized Format) file extension
|
static java.lang.String |
FILE_TYPE_MAP
Map file extension
|
static java.lang.String |
FILE_TYPE_MISSION
Mission file extension
|
static java.lang.String |
FILE_TYPE_MISSION_COMPRESSED
Compressed mission file extension
|
static java.lang.String |
FILE_TYPE_RMF
RMF (REMUS Mission Format) file extension (not used often now)
|
static java.lang.String |
FILE_TYPE_VEHICLE
Vehicle file extension
|
static java.lang.String |
FILE_TYPE_WSN
WSN (Wireless Sensor Network) file extension (not used often now)
|
static java.lang.String |
FILE_TYPE_XML
XML file extension
|
| Modifier and Type | Method and Description |
|---|---|
static void |
appendToFile(java.io.File destination,
java.io.File fileToBeAppended)
This will append one file to the destination.
|
static void |
appendToFile(java.io.File destination,
java.io.InputStream source)
This will appends the source to the destination file and close it.
|
static boolean |
appendToFile(java.lang.String fileName,
java.lang.String dataToSave) |
static boolean |
appendToFile(java.lang.String fileName,
java.lang.String dataToSave,
java.lang.String encoding) |
static boolean |
backupFile(java.lang.String source)
This will create a copy of the given file with the bak extension appended into the name.
|
static java.lang.String |
checkFileForExtensions(java.io.File file,
java.lang.String... extensions)
|
static java.lang.String |
checkFileForExtensions(java.lang.String filePath,
java.lang.String... extensions)
Checks a file name for matching a file extension (case insensitive).
|
static void |
concatFiles(java.io.File destination,
java.io.File fileToBeAppended)
This concatenates two files.
|
static boolean |
copyFile(java.lang.String source,
java.lang.String dest)
This will copy the file to some other.
|
static boolean |
copyFileAndBackup(java.lang.String source,
java.lang.String out)
This will copy the file to some other and also
creates a copy of the given file with the bak extension appended into the name.
|
static boolean |
copyFileToDir(java.lang.String source,
java.lang.String destDir)
This will copy a file to a given folder.
|
static void |
deltree(java.lang.String dir)
Deletes the directory and its content.
|
static java.lang.String |
getAsCompactFormatedXMLString(org.dom4j.Document doc)
This removes all extra spaces and new lines from the XML and return it.
|
static java.lang.String |
getAsCompactFormatedXMLString(org.dom4j.Document doc,
boolean omitDeclaration)
This removes all extra spaces and new lines from the XML and return it.
|
static java.lang.String |
getAsCompactFormatedXMLString(java.lang.String xml)
This removes all extra spaces and new lines from the XML and return it.
|
static java.lang.String |
getAsCompactFormatedXMLString(java.lang.String xml,
boolean omitDeclaration)
This removes all extra spaces and new lines from the XML and return it.
|
static java.lang.String |
getAsPrettyPrintFormatedXMLString(org.dom4j.Document doc)
This will get a flat or partial formated XML string as a formated XML string.
|
static java.lang.String |
getAsPrettyPrintFormatedXMLString(org.dom4j.Document doc,
boolean omitDeclaration)
This will get a flat or partial formated XML string as a formated XML string.
|
static java.lang.String |
getAsPrettyPrintFormatedXMLString(java.lang.String xml)
This will get a flat or partial formated XML string as a formated XML string.
|
static java.lang.String |
getAsPrettyPrintFormatedXMLString(java.lang.String xml,
boolean omitDeclaration)
This will get a flat or partial formated XML string as a formated XML string.
|
static byte[] |
getFileAsByteArray(java.lang.String url)
Return the file as an byte array.
|
static java.lang.String |
getFileAsString(java.io.File fx)
|
static java.lang.String |
getFileAsString(java.lang.String url)
Returns the content of the file as a UTF-8 (or in the encoding
of the file if found,
findOutFileEncoding(byte[])) encoded string. |
static java.lang.String |
getFileExtension(java.io.File fx)
Returns the file extension string.
|
static java.lang.String |
getFileExtension(java.lang.String path)
Returns the file extension string.
|
static java.lang.String |
getFileNameWithoutExtension(java.io.File fx)
Return the file name without extension.
|
static java.lang.String |
getFileNameWithoutExtension(java.lang.String path)
Return the file name without extension.
|
static java.io.File[] |
getFilesFromDisk(java.io.File folderToLoad,
java.lang.String searchPattern)
Get the list of sorted files in folder or null if parent folder doesn't exist or pattern is not valid.
|
static java.io.File[] |
getFoldersFromDisk(java.io.File folderToLoad,
java.lang.String searchPattern)
Get the list of sorted folders in folder or null if parent folder doesn't exist or pattern is not valid.
|
static java.lang.String |
getPackageAsPath(java.lang.Class<?> clazz)
Return the Class package as a path.
|
static java.lang.String |
getPackageAsPath(java.lang.Object obj)
Return the Object package as a path.
|
static java.lang.String |
getResourceAsFile(java.lang.String name)
Return a resource path as a path.
|
static java.lang.String |
getResourceAsFileKeepName(java.lang.String name)
Return a resource path as a path.
|
static java.io.InputStream |
getResourceAsStream(java.lang.String name)
Return a resource path as a input stream.
|
static boolean |
loadLibraryFromResource(java.lang.String libResourcePath)
Loads a library from resource using
System load. |
static void |
main(java.lang.String[] args) |
static java.net.URL |
pathToURL(java.lang.String path)
This will transform a path into a URL.
|
static java.lang.String |
relativizeFilePath(java.lang.String parentPath,
java.lang.String filePath)
This will try to relativize the file path in relation to the other.
|
static java.lang.String |
relativizeFilePathAsURI(java.lang.String parentPath,
java.lang.String filePath)
This will try to relativize the file path in relation to the other as an URI.
|
static java.lang.String |
replaceFileExtension(java.io.File fx,
java.lang.String newExtension)
Return the file name string with the extension replaced.
|
static java.lang.String |
replaceFileExtension(java.lang.String path,
java.lang.String newExtension)
Return the file name string with the extension replaced.
|
static boolean |
saveToFile(java.lang.String fileName,
java.lang.String dataToSave) |
static boolean |
saveToFile(java.lang.String fileName,
java.lang.String dataToSave,
java.lang.String encoding) |
static boolean |
saveToFile(java.lang.String fileName,
java.lang.String dataToSave,
java.lang.String encoding,
boolean append)
This will save the string (dataToSave) to the file with the encoding and appends or overwrite.
|
public static final byte[] BOM_UTF8
public static final byte[] BOM_UTF16LE
public static final byte[] BOM_UTF16BE
public static final byte[] BOM_UTF32LE
public static final byte[] BOM_UTF32BE
public static final java.lang.String FILE_TYPE_MISSION
public static final java.lang.String FILE_TYPE_MISSION_COMPRESSED
public static final java.lang.String FILE_TYPE_MAP
public static final java.lang.String FILE_TYPE_CONSOLE
public static final java.lang.String FILE_TYPE_CONFIG
public static final java.lang.String FILE_TYPE_VEHICLE
public static final java.lang.String FILE_TYPE_CHECKLIST
public static final java.lang.String FILE_TYPE_WSN
public static final java.lang.String FILE_TYPE_INI
public static final java.lang.String FILE_TYPE_RMF
public static final java.lang.String FILE_TYPE_XML
public static final java.lang.String FILE_TYPE_LSF
public static final java.lang.String FILE_TYPE_LSF_COMPRESSED
public static final java.lang.String FILE_TYPE_LSF_COMPRESSED_BZIP2
public static java.lang.String getFileExtension(java.io.File fx)
fx - public static java.lang.String getFileExtension(java.lang.String path)
path - public static java.lang.String getFileNameWithoutExtension(java.io.File fx)
fx - public static java.lang.String getFileNameWithoutExtension(java.lang.String path)
path - public static java.lang.String replaceFileExtension(java.io.File fx,
java.lang.String newExtension)
fx - newExtension - public static java.lang.String replaceFileExtension(java.lang.String path,
java.lang.String newExtension)
path - newExtension - public static java.lang.String checkFileForExtensions(java.io.File file,
java.lang.String... extensions)
file - extensions - public static java.lang.String checkFileForExtensions(java.lang.String filePath,
java.lang.String... extensions)
filePath - extensions - public static java.lang.String getFileAsString(java.io.File fx)
fx - public static java.lang.String getFileAsString(java.lang.String url)
findOutFileEncoding(byte[])) encoded string.url - The URL or relative file path.public static java.io.File[] getFilesFromDisk(java.io.File folderToLoad,
java.lang.String searchPattern)
folderToLoad - searchPattern - null for allpublic static java.io.File[] getFoldersFromDisk(java.io.File folderToLoad,
java.lang.String searchPattern)
folderToLoad - searchPattern - null for allpublic static byte[] getFileAsByteArray(java.lang.String url)
url - The URL or file path for the filepublic static java.lang.String getAsPrettyPrintFormatedXMLString(java.lang.String xml)
getAsPrettyPrintFormatedXMLString(String, boolean) )xml - public static java.lang.String getAsPrettyPrintFormatedXMLString(java.lang.String xml,
boolean omitDeclaration)
xml - omitDeclaration - If the declaration of the XML file is to be included or omitted.public static java.lang.String getAsCompactFormatedXMLString(java.lang.String xml)
getAsCompactFormatedXMLString(String, boolean) )xml - public static java.lang.String getAsCompactFormatedXMLString(java.lang.String xml,
boolean omitDeclaration)
xml - omitDeclaration - If the declaration of the XML file is to be included or omitted.public static java.lang.String getAsPrettyPrintFormatedXMLString(org.dom4j.Document doc)
getAsPrettyPrintFormatedXMLString(Document, boolean) )doc - public static java.lang.String getAsPrettyPrintFormatedXMLString(org.dom4j.Document doc,
boolean omitDeclaration)
doc - omitDeclaration - If the declaration of the XML file is to be included or omitted.public static java.lang.String getAsCompactFormatedXMLString(org.dom4j.Document doc)
getAsCompactFormatedXMLString(String, boolean) )doc - public static java.lang.String getAsCompactFormatedXMLString(org.dom4j.Document doc,
boolean omitDeclaration)
doc - omitDeclaration - If the declaration of the XML file is to be included or omitted.public static void appendToFile(java.io.File destination,
java.io.InputStream source)
throws java.lang.Exception
destination - source - java.lang.Exceptionpublic static void concatFiles(java.io.File destination,
java.io.File fileToBeAppended)
throws java.lang.Exception
destination - fileToBeAppended - java.lang.Exceptionpublic static void appendToFile(java.io.File destination,
java.io.File fileToBeAppended)
throws java.lang.Exception
destination - fileToBeAppended - java.lang.Exceptionpublic static boolean appendToFile(java.lang.String fileName,
java.lang.String dataToSave,
java.lang.String encoding)
fileName - dataToSave - encoding - saveToFile(String, String, String, boolean)public static boolean appendToFile(java.lang.String fileName,
java.lang.String dataToSave)
fileName - dataToSave - saveToFile(String, String, String, boolean)public static boolean saveToFile(java.lang.String fileName,
java.lang.String dataToSave,
java.lang.String encoding)
fileName - dataToSave - encoding - saveToFile(String, String, String, boolean)public static boolean saveToFile(java.lang.String fileName,
java.lang.String dataToSave)
fileName - dataToSave - saveToFile(String, String, String, boolean)public static boolean saveToFile(java.lang.String fileName,
java.lang.String dataToSave,
java.lang.String encoding,
boolean append)
fileName - File path to save to.dataToSave - String with the data.encoding - The encoding of the output file.append - Indicates if the data is to be appended to the file.public static boolean backupFile(java.lang.String source)
source - public static boolean copyFileAndBackup(java.lang.String source,
java.lang.String out)
source - out - public static boolean copyFile(java.lang.String source,
java.lang.String dest)
source - out - public static boolean copyFileToDir(java.lang.String source,
java.lang.String destDir)
source - destDir - public static java.lang.String relativizeFilePathAsURI(java.lang.String parentPath,
java.lang.String filePath)
parentPath - The path to relativize tofilePath - The path to be relativizedpublic static java.lang.String relativizeFilePath(java.lang.String parentPath,
java.lang.String filePath)
parentPath - The path to relativize tofilePath - The path to be relativizedpublic static void deltree(java.lang.String dir)
dir - public static java.net.URL pathToURL(java.lang.String path)
throws java.net.MalformedURLException
path - java.net.MalformedURLExceptionpublic static java.lang.String getResourceAsFile(java.lang.String name)
name - public static java.io.InputStream getResourceAsStream(java.lang.String name)
name - public static java.lang.String getResourceAsFileKeepName(java.lang.String name)
name - public static boolean loadLibraryFromResource(java.lang.String libResourcePath)
System load.libResourcePath - public static java.lang.String getPackageAsPath(java.lang.Object obj)
obj - public static java.lang.String getPackageAsPath(java.lang.Class<?> clazz)
clazz - public static void main(java.lang.String[] args)
throws java.io.IOException
java.io.IOExceptionCopyright © 2004-2020 FEUP-LSTS and Neptus developers. All Rights Reserved.