APIdia Launch Partner
Top Description Inners Fields Constructors Methods
javax.swing.filechooser

public abstract Class FileSystemView

Additional top-level classes in compilation unit: UnixFileSystemView, WindowsFileSystemView, GenericFileSystemView.

extends Object
Class Inheritance
Known Direct Subclasses
javax.swing.filechooser.UnixFileSystemView, javax.swing.filechooser.WindowsFileSystemView, javax.swing.filechooser.GenericFileSystemView
Imports
java.awt.Image, java.awt.image.AbstractMultiResolutionImage, java.beans.PropertyChangeListener, java.io.File, .FileNotFoundException, .IOException, java.lang.ref.WeakReference, java.text.MessageFormat, java.util.ArrayList, .List, javax.swing.Icon, .ImageIcon, .JFileChooser, .UIManager, jdk.internal.ref.CleanerFactory, sun.awt.shell.ShellFolder

FileSystemView is JFileChooser's gateway to the file system. Since the JDK1.1 File API doesn't allow access to such information as root partitions, file type information, or hidden file bits, this class is designed to intuit as much OS-specific file system information as possible.

Java Licensees may want to provide a different implementation of FileSystemView to better handle a given operating system.

Author
Jeff Dinkins

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class

Field Summary

Modifier and TypeField and Description
pack-priv static FileSystemView
pack-priv static FileSystemView
private boolean
pack-priv static FileSystemView

Constructor Summary

AccessConstructor and Description
public
FileSystemView()

Constructs a FileSystemView.

Method Summary

Modifier and TypeMethod and Description
public File

Returns:

a File object created from dir and filename
createFileObject
(File
an abstract pathname denoting a directory
dir
,
String
a String representation of a pathname
filename
)

Returns a File object constructed in dir from the given filename.

public File

Returns:

a File object created from the given path
createFileObject
(String
String representation of path
path
)

Returns a File object constructed from the given path string.

protected File

Returns:

a new File object
createFileSystemRoot
(File
a File object representing a file system root directory, for example "/" on Unix or "C:\" on Windows.
f
)

Creates a new File object for f with correct behavior for a file system root directory.

public abstract File

Returns:

a File object denoting the newly created folder
createNewFolder
(File
a File object denoting directory to contain the new folder
containingDir
)

Creates a new folder with a default folder name.

public File

Returns:

a File object.
getChild
(File
a File object representing a directory or special folder
parent
,
String
a name of a file or folder which exists in parent
fileName
)

Returns a File object which is normally constructed with new File(parent, fileName) except when the parent and child are both special folders, in which case the File is a wrapper containing a ShellFolder object.

public File[]

Returns:

an array of File objects. The array returned may be possibly empty if there are no appropriate permissions.
getChooserComboBoxFiles
()

Returns an array of files representing the values which will be shown in the file chooser selector.

public final File[]

Returns:

an array of File objects. The array returned may be possibly empty if there are no appropriate permissions.
getChooserShortcutPanelFiles
()

Returns an array of files representing the values to show by default in the file chooser shortcuts panel.

public File

Returns:

a File object representing the default starting folder
getDefaultDirectory
()

Return the user's default starting directory for the file chooser.

public File[]

Returns:

an array of File objects representing files and directories in the given dir. It includes hidden files if useFileHiding is false.
getFiles
(File
the root directory of files to be returned
dir
,
boolean
determine if hidden files are returned
useFileHiding
)

Gets the list of shown (i.e. not hidden) files.

public static FileSystemView

Returns:

the file system view
getFileSystemView
()

Returns the file system view.

public File

Returns:

the home directory
getHomeDirectory
()

Returns the home directory.

public File

Returns:

the linked file or null.
getLinkLocation
(File
a file
file
)

Returns the regular file referenced by the specified link file if the specified file is a shell interpreted link.

public File

Returns:

the parent directory of dir, or null if dir is null
getParentDirectory
(File
the File being queried
dir
)

Returns the parent directory of dir.

public File[]

Returns:

an array of File objects representing all root partitions on this system
getRoots
()

Returns all root partitions on this system.

pack-priv ShellFolder
getShellFolder(File f)

Throws FileNotFoundException if file not found or current thread was interrupted

public String

Returns:

the file name as it would be displayed by a native file chooser
getSystemDisplayName
(File
a File object
f
)

Name of a file, directory, or folder as it would be displayed in a system file browser.

public Icon

Returns:

an icon as it would be displayed by a native file chooser
getSystemIcon
(File
a File object
f
)

Icon for a file, directory, or folder as it would be displayed in a system file browser.

public Icon

Returns:

an icon as it would be displayed by a native file chooser or null for a non-existent or inaccessible file.
getSystemIcon
(File
a File object for which the icon will be retrieved
f
,
int
width of the icon in user coordinate system.
width
,
int
height of the icon in user coordinate system.
height
)

Returns an icon for a file, directory, or folder as it would be displayed in a system file browser for the requested size.

public String

Returns:

the file type description as it would be displayed by a native file chooser or null if no native information is available.
getSystemTypeDescription
(File
a File object
f
)

Type description for a file, directory, or folder as it would be displayed in a system file browser.

public boolean

Returns:

false always
isComputerNode
(File
a directory
dir
)

Used by UI classes to decide whether to display a special icon for a computer node, e.g. "My Computer" or a network server.

public boolean

Returns:

false always
isDrive
(File
a directory
dir
)

Used by UI classes to decide whether to display a special icon for drives or partitions, e.g. a "hard disk" icon.

public boolean

Returns:

true if f is a real file or directory.
isFileSystem
(File
a File object
f
)

Checks if f represents a real directory or file as opposed to a special folder such as "Desktop".

public boolean

Returns:

true if f is a root of a filesystem
isFileSystemRoot
(File
a File object representing a directory
dir
)

Is dir the root of a tree in the file system, such as a drive or partition.

public boolean

Returns:

false always
isFloppyDrive
(File
a directory
dir
)

Used by UI classes to decide whether to display a special icon for a floppy disk.

public boolean

Returns:

true if the given File denotes a hidden file
isHiddenFile
(File
a File object
f
)

Returns whether a file is hidden or not.

public boolean

Returns:

true if folder is a directory or special folder and contains file.
isParent
(File
a File object representing a directory or special folder
folder
,
File
a File object
file
)

On Windows, a file can appear in multiple folders, other than its parent directory in the filesystem.

public boolean

Returns:

true if f is a root in the navigable tree.
isRoot
(File
a File object representing a directory
f
)

Determines if the given file is a root in the navigable tree(s).

public Boolean

Returns:

true if the file/directory can be traversed, otherwise false
isTraversable
(File
the File
f
)

Returns true if the file (directory) can be visited.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

genericFileSystemViewback to summary
pack-priv static FileSystemView genericFileSystemView
unixFileSystemViewback to summary
pack-priv static FileSystemView unixFileSystemView
useSystemExtensionHidingback to summary
private boolean useSystemExtensionHiding
windowsFileSystemViewback to summary
pack-priv static FileSystemView windowsFileSystemView

Constructor Detail

FileSystemViewback to summary
public FileSystemView()

Constructs a FileSystemView.

Method Detail

createFileObjectback to summary
public File createFileObject(File dir, String filename)

Returns a File object constructed in dir from the given filename.

Parameters
dir:File

an abstract pathname denoting a directory

filename:String

a String representation of a pathname

Returns:File

a File object created from dir and filename

createFileObjectback to summary
public File createFileObject(String path)

Returns a File object constructed from the given path string.

Parameters
path:String

String representation of path

Returns:File

a File object created from the given path

createFileSystemRootback to summary
protected File createFileSystemRoot(File f)

Creates a new File object for f with correct behavior for a file system root directory.

Parameters
f:File

a File object representing a file system root directory, for example "/" on Unix or "C:\" on Windows.

Returns:File

a new File object

Since
1.4
createNewFolderback to summary
public abstract File createNewFolder(File containingDir) throws IOException

Creates a new folder with a default folder name.

Parameters
containingDir:File

a File object denoting directory to contain the new folder

Returns:File

a File object denoting the newly created folder

Exceptions
IOException:
if new folder could not be created
getChildback to summary
public File getChild(File parent, String fileName)

Returns a File object which is normally constructed with new File(parent, fileName) except when the parent and child are both special folders, in which case the File is a wrapper containing a ShellFolder object.

Parameters
parent:File

a File object representing a directory or special folder

fileName:String

a name of a file or folder which exists in parent

Returns:File

a File object.

Since
1.4
getChooserComboBoxFilesback to summary
public File[] getChooserComboBoxFiles()

Returns an array of files representing the values which will be shown in the file chooser selector.

Returns:File[]

an array of File objects. The array returned may be possibly empty if there are no appropriate permissions.

Since
9
getChooserShortcutPanelFilesback to summary
public final File[] getChooserShortcutPanelFiles()

Returns an array of files representing the values to show by default in the file chooser shortcuts panel.

Returns:File[]

an array of File objects. The array returned may be possibly empty if there are no appropriate permissions.

Since
12
getDefaultDirectoryback to summary
public File getDefaultDirectory()

Return the user's default starting directory for the file chooser.

Returns:File

a File object representing the default starting folder

Since
1.4
getFilesback to summary
public File[] getFiles(File dir, boolean useFileHiding)

Gets the list of shown (i.e. not hidden) files.

Parameters
dir:File

the root directory of files to be returned

useFileHiding:boolean

determine if hidden files are returned

Returns:File[]

an array of File objects representing files and directories in the given dir. It includes hidden files if useFileHiding is false.

getFileSystemViewback to summary
public static FileSystemView getFileSystemView()

Returns the file system view.

Returns:FileSystemView

the file system view

getHomeDirectoryback to summary
public File getHomeDirectory()

Returns the home directory.

Returns:File

the home directory

getLinkLocationback to summary
public File getLinkLocation(File file) throws FileNotFoundException

Returns the regular file referenced by the specified link file if the specified file is a shell interpreted link. Returns null if the specified file is not a shell interpreted link.

Parameters
file:File

a file

Returns:File

the linked file or null.

Exceptions
FileNotFoundException:
if the linked file does not exist
NullPointerException:
if file equals null
Since
9
getParentDirectoryback to summary
public File getParentDirectory(File dir)

Returns the parent directory of dir.

Parameters
dir:File

the File being queried

Returns:File

the parent directory of dir, or null if dir is null

getRootsback to summary
public File[] getRoots()

Returns all root partitions on this system. For example, on Windows, this would be the "Desktop" folder, while on DOS this would be the A: through Z: drives.

Returns:File[]

an array of File objects representing all root partitions on this system

getShellFolderback to summary
pack-priv ShellFolder getShellFolder(File f) throws FileNotFoundException

Throws FileNotFoundException if file not found or current thread was interrupted

getSystemDisplayNameback to summary
public String getSystemDisplayName(File f)

Name of a file, directory, or folder as it would be displayed in a system file browser. Example from Windows: the "M:\" directory displays as "CD-ROM (M:)" The default implementation gets information from the ShellFolder class.

Parameters
f:File

a File object

Returns:String

the file name as it would be displayed by a native file chooser

Since
1.4
See Also
JFileChooser#getName
getSystemIconback to summary
public Icon getSystemIcon(File f)

Icon for a file, directory, or folder as it would be displayed in a system file browser. Example from Windows: the "M:\" directory displays a CD-ROM icon.

The default implementation gets information from the ShellFolder class.

Parameters
f:File

a File object

Returns:Icon

an icon as it would be displayed by a native file chooser

Since
1.4
See Also
JFileChooser#getIcon
getSystemIconback to summary
public Icon getSystemIcon(File f, int width, int height)

Returns an icon for a file, directory, or folder as it would be displayed in a system file browser for the requested size.

Example:

    FileSystemView fsv = FileSystemView.getFileSystemView();
    Icon icon = fsv.getSystemIcon(new File("application.exe"), 64, 64);
    JLabel label = new JLabel(icon);

Implementation Specification

The available icons may be platform specific and so the available sizes determined by the platform. Therefore an exact match for the requested size may not be possible. The icon returned may be a multi-resolution icon image, which allows better support for High DPI environments with different scaling factors.

Parameters
f:File

a File object for which the icon will be retrieved

width:int

width of the icon in user coordinate system.

height:int

height of the icon in user coordinate system.

Returns:Icon

an icon as it would be displayed by a native file chooser or null for a non-existent or inaccessible file.

Exceptions
IllegalArgumentException:
if an invalid parameter such as a negative size or a null file reference is passed.
Since
17
See Also
JFileChooser#getIcon, AbstractMultiResolutionImage, FileSystemView#getSystemIcon(File)
getSystemTypeDescriptionback to summary
public String getSystemTypeDescription(File f)

Type description for a file, directory, or folder as it would be displayed in a system file browser. Example from Windows: the "Desktop" folder is described as "Desktop". Override for platforms with native ShellFolder implementations.

Parameters
f:File

a File object

Returns:String

the file type description as it would be displayed by a native file chooser or null if no native information is available.

Since
1.4
See Also
JFileChooser#getTypeDescription
isComputerNodeback to summary
public boolean isComputerNode(File dir)

Used by UI classes to decide whether to display a special icon for a computer node, e.g. "My Computer" or a network server. The default implementation has no way of knowing, so always returns false.

Parameters
dir:File

a directory

Returns:boolean

false always

Since
1.4
isDriveback to summary
public boolean isDrive(File dir)

Used by UI classes to decide whether to display a special icon for drives or partitions, e.g. a "hard disk" icon. The default implementation has no way of knowing, so always returns false.

Parameters
dir:File

a directory

Returns:boolean

false always

Since
1.4
isFileSystemback to summary
public boolean isFileSystem(File f)

Checks if f represents a real directory or file as opposed to a special folder such as "Desktop". Used by UI classes to decide if a folder is selectable when doing directory choosing.

Parameters
f:File

a File object

Returns:boolean

true if f is a real file or directory.

Since
1.4
isFileSystemRootback to summary
public boolean isFileSystemRoot(File dir)

Is dir the root of a tree in the file system, such as a drive or partition. Example: Returns true for "C:\" on Windows 98.

Parameters
dir:File

a File object representing a directory

Returns:boolean

true if f is a root of a filesystem

Since
1.4
See Also
isRoot
isFloppyDriveback to summary
public boolean isFloppyDrive(File dir)

Used by UI classes to decide whether to display a special icon for a floppy disk. Implies isDrive(dir). The default implementation has no way of knowing, so always returns false.

Parameters
dir:File

a directory

Returns:boolean

false always

Since
1.4
isHiddenFileback to summary
public boolean isHiddenFile(File f)

Returns whether a file is hidden or not.

Parameters
f:File

a File object

Returns:boolean

true if the given File denotes a hidden file

isParentback to summary
public boolean isParent(File folder, File file)

On Windows, a file can appear in multiple folders, other than its parent directory in the filesystem. Folder could for example be the "Desktop" folder which is not the same as file.getParentFile().

Parameters
folder:File

a File object representing a directory or special folder

file:File

a File object

Returns:boolean

true if folder is a directory or special folder and contains file.

Since
1.4
isRootback to summary
public boolean isRoot(File f)

Determines if the given file is a root in the navigable tree(s). Examples: Windows 98 has one root, the Desktop folder. DOS has one root per drive letter, C:\, D:\, etc. Unix has one root, the "/" directory. The default implementation gets information from the ShellFolder class.

Parameters
f:File

a File object representing a directory

Returns:boolean

true if f is a root in the navigable tree.

See Also
isFileSystemRoot
isTraversableback to summary
public Boolean isTraversable(File f)

Returns true if the file (directory) can be visited. Returns false if the directory cannot be traversed.

Parameters
f:File

the File

Returns:Boolean

true if the file/directory can be traversed, otherwise false

Since
1.4
See Also
JFileChooser#isTraversable, FileView#isTraversable
javax.swing.filechooser back to summary

pack-priv Class FileSystemView.FileSystemRoot

extends File
Class Inheritance
Annotations
@SuppressWarnings:serial

Field Summary

Inherited from java.io.File:
pathSeparatorpathSeparatorCharseparatorseparatorChar

Constructor Summary

AccessConstructor and Description
public
public

Method Summary

Modifier and TypeMethod and Description
public String
getName()

Overrides java.io.File.getName.

Returns the name component of this abstract pathname.

public boolean
isDirectory()

Overrides java.io.File.isDirectory.

Tests whether the file located by this abstract pathname is a directory.

Inherited from java.io.File:
canExecutecanReadcanWritecompareTocreateNewFilecreateTempFilecreateTempFiledeletedeleteOnExitequalsexistsgetAbsoluteFilegetAbsolutePathgetCanonicalFilegetCanonicalPathgetFreeSpacegetParentgetParentFilegetPathgetTotalSpacegetUsableSpacehashCodeisAbsoluteisFileisHiddenlastModifiedlengthlistlistlistFileslistFileslistFileslistRootsmkdirmkdirsrenameTosetExecutablesetExecutablesetLastModifiedsetReadablesetReadablesetReadOnlysetWritablesetWritabletoPathtoStringtoURItoURL

Constructor Detail

FileSystemRootback to summary
public FileSystemRoot(File f)
FileSystemRootback to summary
public FileSystemRoot(String s)

Method Detail

getNameback to summary
public String getName()

Overrides java.io.File.getName.

Doc from java.io.File.getName.

Returns the name component of this abstract pathname. This is just the last name in the pathname's name sequence. If the pathname's name sequence is empty, then the empty string is returned.

isDirectoryback to summary
public boolean isDirectory()

Overrides java.io.File.isDirectory.

Doc from java.io.File.isDirectory.

Tests whether the file located by this abstract pathname is a directory.

Where it is required to distinguish an I/O exception from the case that the file is not a directory, or where several attributes of the same file are required at the same time, then the Files.readAttributes method may be used.