Package com.onenetwork.platform.tools.io
Class Files
java.lang.Object
com.onenetwork.platform.tools.io.Files
public class Files
extends java.lang.Object
Utility class for
File
related operations-
Constructor Summary
Constructors Constructor Description Files()
-
Method Summary
Modifier and Type Method Description static byte[]
contents(java.io.File file)
Returns the contents of the supplied File as an array of bytes.static java.lang.String
contentsAsString(java.io.File file)
Returns the contents of the supplied file as a String.static java.lang.String
contentsAsString(java.io.File file, java.lang.String encoding)
Returns the contents of the supplied file as a String.static void
copyContent(java.io.File source, java.io.File destination, boolean removeSource)
Reads the file content from source file and writes to the destination file
-
Constructor Details
-
Files
public Files()
-
-
Method Details
-
copyContent
public static void copyContent(java.io.File source, java.io.File destination, boolean removeSource) throws java.io.IOExceptionReads the file content from source file and writes to the destination file- Parameters:
source
- File to copy fromdestination
- File to copy toremoveSource
- if true then method works as move file operation- Throws:
java.io.IOException
- thrown if there is an I/O problem
-
contentsAsString
public static java.lang.String contentsAsString(java.io.File file) throws java.io.IOExceptionReturns the contents of the supplied file as a String.- Parameters:
file
- file whose String contents should be read from disk- Returns:
- the contents of the supplied File as a String (the assumption is made that the bytes contained in the File can be used to construct a meaningful String)
- Throws:
java.io.IOException
- thrown if there is an error when attempting to read the supplied File
-
contentsAsString
public static java.lang.String contentsAsString(java.io.File file, java.lang.String encoding) throws java.io.IOExceptionReturns the contents of the supplied file as a String.- Parameters:
file
- file whose String contents should be read from diskencoding
- file encoding to use- Returns:
- the contents of the supplied File as a String (the assumption is made that the bytes contained in the File can be used to construct a meaningful String)
- Throws:
java.io.IOException
- thrown if there is an error when attempting to read the supplied File
-
contents
public static byte[] contents(java.io.File file) throws java.io.IOExceptionReturns the contents of the supplied File as an array of bytes.- Parameters:
file
- file whose contents should be read from disk- Returns:
- the contents of the supplied File
- Throws:
java.io.IOException
- thrown if there is an error when attempting to read the supplied File
-