Provides file access for workspace and file system resources. Methods accepting location objects can deal with String, URI, IFile and File instances.
Constant | Description |
---|---|
APPEND | Access modifier for append mode (4). |
READ | Access modifier for read mode (1). |
WRITE | Access modifier for write mode (2). |
Method | Description |
---|---|
closeFile() | Close a file. |
copyFile() | Copies a file from location to targetLocation. |
createFile() | Create a new file in the workspace or the file system. |
createFolder() | Create a new folder in the workspace or the file system. |
createProblemMarker() | Create a problem marker on a file resource. |
createProject() | Create a new workspace project. |
deleteFile() | Delete a file from the workspace or local file system. |
deleteFolder() | Delete a folder from the workspace or local file system. |
deleteProject() | Delete a project from the workspace. |
fileExists() | Verifies that a specific file exists. |
findFiles() | Return files matching a certain pattern. |
getFile() | Get a workspace or file system file. |
getProject() | Get a project instance. |
getWorkspace() | Get the workspace root. |
linkProject() | Links a project into the current workspace. |
openFile() | Opens a file from the workspace or the file system. |
readFile() | Read data from a file. |
readLine() | Read a single line from a file. |
readStream() | Read from an InputStream into a string. |
refreshResource() | Refresh a given resource and all its child elements. |
showFileSelectionDialog() | Opens a file dialog. |
showFolderSelectionDialog() | Opens a dialog box which allows the user to select a container (project or folder). |
writeFile() | Write data to a file. |
writeLine() | Write a line of data to a file. |
void closeFile(IFileHandle handle)
Close a file. Releases system resources bound by an open file.
void copyFile(Object sourceLocation, Object targetLocation)
Copies a file from location to targetLocation.
Object createFile(Object location)
Create a new file in the workspace or the file system.
IFile, File or null
in case of error
Object createFolder(Object location)
Create a new folder in the workspace or the file system.
IFolder, File or null
in case of error
IWorkspace.validateName
).force
is false
.IResourceChangeEvent
for
more details.void createProblemMarker(String severity, Object location, int lineNumber, String message, [String type], [boolean permanent])
Create a problem marker on a file resource.
true
for permanent markers, false
for temporary markersOptional: defaults to <true>.IProject createProject(String name)
Create a new workspace project. Will create a new project if it not already exists. If creation fails, null
is returned.
null
or project
void deleteFile(Object source)
Delete a file from the workspace or local file system.
void deleteFolder(Object source)
Delete a folder from the workspace or local file system.
void deleteProject(Object source)
Delete a project from the workspace.
boolean fileExists(Object location)
Verifies that a specific file exists.
true
if file exists
Object findFiles(String pattern, [Object rootFolder], [boolean recursive])
Return files matching a certain pattern.
null
for workspace rootOptional: defaults to <null>.true
Optional: defaults to <true>.An array of all matching files
Object getFile(String location, [boolean exists])
Get a workspace or file system file. Resolves relative and absolute file locations. Relative files are resolved against the current script file. If
exists is false
this method also returns files that do not exist yet. If true
only existing instances are returned.
resolved IFile or File instance
IProject getProject(String name)
Get a project instance.
project or null
boolean linkProject(String location)
Links a project into the current workspace. Does not copy resources to the workspace.
link result
IFileHandle openFile(Object location, [int mode], [boolean autoClose])
Opens a file from the workspace or the file system. If the file does not exist and we open it for writing, the file is created automatically.
file handle instance to be used for file modification commands
String readFile(Object location, [int bytes])
Read data from a file. To repeatedly read from a file retrieve a IFileHandle first using openFile() and use the handle for location.
file data or null
if EOF is reached
String readLine(Object location)
Read a single line from a file. To repeatedly read from a file retrieve a IFileHandle first using openFile() and use the handle for location.
line of text or null
if EOF is reached
String readStream(InputStream input)
Read from an InputStream into a string. Consumes an InputStream and stores all available data in a string. Usually a stream is only readable once.
string content of stream.
void refreshResource(Object resource)
Refresh a given resource and all its child elements.
String showFileSelectionDialog([Object rootFolder], [int type], [String title], [String message])
Opens a file dialog. Depending on the rootFolder a workspace dialog or a file system dialog will be used. If the folder cannot be located, the workspace root folder is used by default. When type is set to WRITE or APPEND a save dialog will be shown instead of the default open dialog.
full path to selected file
String showFolderSelectionDialog([Object rootFolder], [String title], [String message])
Opens a dialog box which allows the user to select a container (project or folder). Workspace paths will always display the workspace as root object.
path to selected folder
IFileHandle writeFile(Object location, Object data, [int mode], [boolean autoClose])
Write data to a file. When not using an IFileHandle, previous file content will be overridden. Files that do not exist yet will be automatically created. After the write operation the file remains open. It needs to be closed explicitly using the closeFile() command
file handle to continue write operations
IFileHandle writeLine(Object location, String data, [int mode], [boolean autoClose])
Write a line of data to a file. When not using an IFileHandle, previous file content will be overridden. Files that do not exist yet will be automatically created.
file handle to continue write operations