Package com.mku.file
Class JavaFile
java.lang.Object
com.mku.file.JavaFile
- All Implemented Interfaces:
IRealFile
Salmon RealFile implementation for Java.
-
Field Summary
Fields inherited from interface com.mku.file.IRealFile
autoRename -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionMove this file or directory under a new directory.Move this file or directory under a new directory.Move this file or directory under a new directory.createDirectory(String dirName) Create a directory under this directory.createFile(String filename) Create a file under this directory.booleandelete()Delete this file or directory.booleanexists()True if file or directory exists.Get the absolute path on the physical disk.Get the name of this file or directory.Get the file or directory under this directory with the provided name.intGet the count of files and subdirectoriesGet a stream for reading the file.Get a stream for writing to this file.Get the parent directory of this file or directory.getPath()Get the path of this file.booleanTrue if this is a directory.booleanisFile()True if this is a file.longGet the last modified date on disk.longlength()Get the size of the file on disk.List all files under this directory.booleanmkdir()Create this directory under the current filepath.Move this file or directory under a new directory.Move this file or directory under a new directory.Move this file or directory under a new directory.booleanRename the current file or directory.toString()Returns a string representation of this objectMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.mku.file.IRealFile
copyRecursively, copyRecursively, deleteRecursively, moveRecursively, moveRecursively
-
Constructor Details
-
JavaFile
Instantiate a real file represented by the filepath provided.- Parameters:
path- The filepath.
-
-
Method Details
-
createDirectory
Create a directory under this directory.- Specified by:
createDirectoryin interfaceIRealFile- Parameters:
dirName- The name of the new directory.- Returns:
- The newly created directory.
-
createFile
Create a file under this directory.- Specified by:
createFilein interfaceIRealFile- Parameters:
filename- The name of the new file.- Returns:
- The newly created file.
- Throws:
IOException- Thrown if there is an IO error.
-
delete
public boolean delete()Delete this file or directory. -
exists
public boolean exists()True if file or directory exists. -
getAbsolutePath
Get the absolute path on the physical disk. For java this is the same as the filepath.- Specified by:
getAbsolutePathin interfaceIRealFile- Returns:
- The absolute path.
-
getBaseName
Get the name of this file or directory.- Specified by:
getBaseNamein interfaceIRealFile- Returns:
- The name of this file or directory.
-
getInputStream
Get a stream for reading the file.- Specified by:
getInputStreamin interfaceIRealFile- Returns:
- The stream to read from.
- Throws:
FileNotFoundException- Thrown if file not found
-
getOutputStream
Get a stream for writing to this file.- Specified by:
getOutputStreamin interfaceIRealFile- Returns:
- The stream to write to.
- Throws:
FileNotFoundException- Thrown if file not found
-
getParent
Get the parent directory of this file or directory. -
getPath
Get the path of this file. For java this is the same as the absolute filepath. -
isDirectory
public boolean isDirectory()True if this is a directory.- Specified by:
isDirectoryin interfaceIRealFile- Returns:
- True if it's a directory.
-
isFile
public boolean isFile()True if this is a file. -
lastModified
public long lastModified()Get the last modified date on disk.- Specified by:
lastModifiedin interfaceIRealFile- Returns:
- The last modified date in milliseconds
-
length
public long length()Get the size of the file on disk. -
getChildrenCount
public int getChildrenCount()Get the count of files and subdirectories- Specified by:
getChildrenCountin interfaceIRealFile- Returns:
- The children count
-
listFiles
List all files under this directory. -
move
Move this file or directory under a new directory. -
move
Move this file or directory under a new directory. -
move
Move this file or directory under a new directory. -
copy
Move this file or directory under a new directory.- Specified by:
copyin interfaceIRealFile- Parameters:
newDir- The target directory.- Returns:
- The copied file. Use this file for subsequent operations instead of the original.
- Throws:
IOException- Thrown if there is an IO error.
-
copy
Move this file or directory under a new directory.- Specified by:
copyin interfaceIRealFile- Parameters:
newDir- The target directory.newName- New filename- Returns:
- The copied file. Use this file for subsequent operations instead of the original.
- Throws:
IOException- Thrown if there is an IO error.
-
copy
public IRealFile copy(IRealFile newDir, String newName, BiConsumer<Long, Long> progressListener) throws IOExceptionMove this file or directory under a new directory.- Specified by:
copyin interfaceIRealFile- Parameters:
newDir- The target directory.newName- New filenameprogressListener- Observer to notify when progress changes.- Returns:
- The copied file. Use this file for subsequent operations instead of the original.
- Throws:
IOException- Thrown if there is an IO error.
-
getChild
Get the file or directory under this directory with the provided name. -
renameTo
Rename the current file or directory. -
mkdir
public boolean mkdir()Create this directory under the current filepath. -
toString
Returns a string representation of this object
-