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
-
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.boolean
delete()
Delete this file or directory.boolean
exists()
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.int
Get 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.boolean
True if this is a directory.boolean
isFile()
True if this is a file.long
Get the last modified date on disk.long
length()
Get the size of the file on disk.List all files under this directory.boolean
mkdir()
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.boolean
Rename 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, wait
Methods 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:
createDirectory
in interfaceIRealFile
- Parameters:
dirName
- The name of the new directory.- Returns:
- The newly created directory.
-
createFile
Create a file under this directory.- Specified by:
createFile
in 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:
getAbsolutePath
in interfaceIRealFile
- Returns:
- The absolute path.
-
getBaseName
Get the name of this file or directory.- Specified by:
getBaseName
in interfaceIRealFile
- Returns:
- The name of this file or directory.
-
getInputStream
Get a stream for reading the file.- Specified by:
getInputStream
in 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:
getOutputStream
in 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:
isDirectory
in 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:
lastModified
in 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:
getChildrenCount
in 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:
copy
in 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:
copy
in 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:
copy
in 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
-