Class FileHandlingFunctions
java.lang.Object
com.scriptbasic.utility.functions.file.FileHandlingFunctions
public class FileHandlingFunctions
extends java.lang.Object
This class implements static methods, which can be used from BASIC programs
to access the file system.
Note that these functions are NOT registered into the BASIC interpreter by default. The embedding application has to ask the interpreter to register the methods of this class if it wants BASIC programs access the file system.
- Author:
- Peter Verhas
-
Method Summary
Modifier and Type Method Description static java.lang.StringabsoluteFileName(java.lang.String fileName)static voidclose(FileHandler fh)static voiddeleteFile(java.lang.String fileName)static booleanfileCanExecute(java.lang.String fileName)static booleanfileExists(java.lang.String fileName)static booleanfileIsExecutable(java.lang.String fileName)static booleanfileIsReadable(java.lang.String fileName)static booleanfileIsWritable(java.lang.String fileName)static java.lang.LongfileLength(java.lang.String fileName)static java.lang.LongfreeSpace(java.lang.String fileName)static booleanisDirectory(java.lang.String fileName)static booleanisFile(java.lang.String fileName)static booleanisHidden(java.lang.String fileName)static java.lang.LonglastModified(java.lang.String fileName)static BasicArraylistFiles(java.lang.String fileName)static booleanmkdir(java.lang.String fileName)static FileHandleropen(java.lang.String fileName, java.lang.String mode)Opens a file and returns a file handler.static java.lang.StringparentDirectory(java.lang.String fileName)static voidprintf(FileHandler fh, java.lang.String line)static voidprintfln(FileHandler fh, java.lang.String line)static byte[]read(FileHandler fh, int len)static java.lang.StringreadLine(FileHandler fh)static booleanrenameFile(java.lang.String fileNameFrom, java.lang.String fileNameTo)static booleansetExecutable(java.lang.String fileName, boolean executable, boolean ownerOnly)static booleansetLastModified(java.lang.String fileName, java.lang.Long time)static booleansetReadable(java.lang.String fileName, boolean readable, boolean ownerOnly)static booleansetRedOnly(java.lang.String fileName)static booleansetWritable(java.lang.String fileName, boolean writable, boolean ownerOnly)static voidwrite(FileHandler fh, byte[] buffer)
-
Method Details
-
open
Opens a file and returns a file handler. Files can be opened read, write or append. Also the mode can be binary or text. Default is read and text.- Parameters:
fileName- the name of the file to be opened.mode- the mode how to open the file- Returns:
- return value
-
readLine
public static java.lang.String readLine(FileHandler fh) throws BasicRuntimeException, java.io.IOException- Throws:
BasicRuntimeExceptionjava.io.IOException
-
read
public static byte[] read(FileHandler fh, int len) throws BasicRuntimeException, java.io.IOException- Throws:
BasicRuntimeExceptionjava.io.IOException
-
printf
public static void printf(FileHandler fh, java.lang.String line) throws BasicRuntimeException, java.io.IOException- Throws:
BasicRuntimeExceptionjava.io.IOException
-
printfln
public static void printfln(FileHandler fh, java.lang.String line) throws java.io.IOException, BasicRuntimeException- Throws:
java.io.IOExceptionBasicRuntimeException
-
write
public static void write(FileHandler fh, byte[] buffer) throws BasicRuntimeException, java.io.IOException- Throws:
BasicRuntimeExceptionjava.io.IOException
-
close
- Throws:
java.lang.Exception
-
deleteFile
public static void deleteFile(java.lang.String fileName) -
fileExists
public static boolean fileExists(java.lang.String fileName) -
fileCanExecute
public static boolean fileCanExecute(java.lang.String fileName) -
fileIsReadable
public static boolean fileIsReadable(java.lang.String fileName) -
fileIsWritable
public static boolean fileIsWritable(java.lang.String fileName) -
fileIsExecutable
public static boolean fileIsExecutable(java.lang.String fileName) -
isDirectory
public static boolean isDirectory(java.lang.String fileName) -
isFile
public static boolean isFile(java.lang.String fileName) -
absoluteFileName
public static java.lang.String absoluteFileName(java.lang.String fileName) -
freeSpace
public static java.lang.Long freeSpace(java.lang.String fileName) -
parentDirectory
public static java.lang.String parentDirectory(java.lang.String fileName) -
isHidden
public static boolean isHidden(java.lang.String fileName) -
mkdir
public static boolean mkdir(java.lang.String fileName) -
renameFile
public static boolean renameFile(java.lang.String fileNameFrom, java.lang.String fileNameTo) -
setExecutable
public static boolean setExecutable(java.lang.String fileName, boolean executable, boolean ownerOnly) -
setReadable
public static boolean setReadable(java.lang.String fileName, boolean readable, boolean ownerOnly) -
setWritable
public static boolean setWritable(java.lang.String fileName, boolean writable, boolean ownerOnly) -
setRedOnly
public static boolean setRedOnly(java.lang.String fileName) -
lastModified
public static java.lang.Long lastModified(java.lang.String fileName) -
fileLength
public static java.lang.Long fileLength(java.lang.String fileName) -
setLastModified
public static boolean setLastModified(java.lang.String fileName, java.lang.Long time) -
listFiles
- Throws:
ScriptBasicException
-