Class FileUtils
java.lang.Object
com.ibm.wsspi.kernel.service.utils.FileUtils
A set of utilities for working with Files
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
ensureDirExists
(File dir) static boolean
fileCanRead
(File target) Execute theFile.canRead()
from within aPrivilegedAction
.static boolean
fileCanWrite
(File target) Execute theFile.canWrite()
from within aPrivilegedAction
.static Boolean
fileCreate
(File target) CallsFile.createNewFile()
on the specifiedtarget
static boolean
fileDelete
(File file) Delete filestatic boolean
fileExists
(File target) Execute theFile.exists()
from within aPrivilegedAction
.static boolean
fileIsDirectory
(File target) Execute theFile.isDirectory()
from within aPrivilegedAction
.static boolean
fileIsFile
(File target) Execute theFile.isFile()
from within aPrivilegedAction
.static long
fileLastModified
(File target) Execute theFile.lastModified()
from within aPrivilegedAction
.static long
fileLength
(File target) Execute theFile.length()
from within aPrivilegedAction
.static boolean
static boolean
fileMkDirs
(File target) static FileOutputStream
getFileOutputStream
(File target) Create a newFileOutputStream
for the file within aPrivilegedAction
.static InputStream
getInputStream
(File target) Create a newInputStream
for the file within aPrivilegedAction
.static String[]
Execute theFile.list()
from within aPrivilegedAction
.static File[]
Execute theFile.listFiles()
from within aPrivilegedAction
.static boolean
setUserReadWriteOnly
(File file) Set the file permissions of the file to be user rw only.static boolean
tryToClose
(Closeable closeable) Close the closeable object
-
Constructor Details
-
FileUtils
public FileUtils()
-
-
Method Details
-
fileIsFile
Execute theFile.isFile()
from within aPrivilegedAction
.- Parameters:
f
-- Returns:
-
fileIsDirectory
Execute theFile.isDirectory()
from within aPrivilegedAction
.- Parameters:
f
-- Returns:
-
fileExists
Execute theFile.exists()
from within aPrivilegedAction
.- Parameters:
target
-- Returns:
-
fileLength
Execute theFile.length()
from within aPrivilegedAction
.- Parameters:
target
-- Returns:
-
listFiles
Execute theFile.listFiles()
from within aPrivilegedAction
.- Parameters:
f
-- Returns:
-
list
Execute theFile.list()
from within aPrivilegedAction
.- Parameters:
f
-- Returns:
-
getInputStream
Create a newInputStream
for the file within aPrivilegedAction
.- Throws:
FileNotFoundException
-
getFileOutputStream
Create a newFileOutputStream
for the file within aPrivilegedAction
.- Throws:
FileNotFoundException
-
fileLastModified
Execute theFile.lastModified()
from within aPrivilegedAction
.- Parameters:
target
- The file to get the last modified for- Returns:
- The last modified for the file
-
fileCanRead
Execute theFile.canRead()
from within aPrivilegedAction
.- Parameters:
target
- The file to test if it can be read- Returns:
true
if the file can be read
-
fileCanWrite
Execute theFile.canWrite()
from within aPrivilegedAction
.- Parameters:
target
- The file to test if it can be written- Returns:
true
if the file can be written
-
fileMkDirs
- Parameters:
target
- The tarket to make a directory for- Returns:
true
if this succeeded.
-
fileMkDir
- Parameters:
target
- The tarket to make a directory for- Returns:
true
if this succeeded.
-
fileDelete
Delete file- Returns:
true
if file was deleted
-
ensureDirExists
- Parameters:
target
- The target to check for existence or to create if it doesn't exist- Returns:
true
if either call succeeded.
-
tryToClose
Close the closeable object- Parameters:
closeable
-
-
setUserReadWriteOnly
Set the file permissions of the file to be user rw only.This is a best effort attempt as Windows does NOT play nicely with file perms.
- Parameters:
an
- existing File
-
fileCreate
CallsFile.createNewFile()
on the specifiedtarget
- Parameters:
target
- The target to create if it doesn't exist- Returns:
true
if call succeeded.- Throws:
IOException
-