Free App To Download _BEST_ Zip Files

0 views
Skip to first unread message

Guy Clena

unread,
Jan 20, 2024, 12:30:16 PMJan 20
to tamimettra

In most cases, the methods defined here will delegate to the associated file system provider to perform the file operations.Since:1.7Method SummaryAll Methods Static Methods Concrete Methods Modifier and TypeMethod and Descriptionstatic longcopy(InputStream in, Path target, CopyOption... options)Copies all bytes from an input stream to a file.static longcopy(Path source, OutputStream out)Copies all bytes from a file to an output stream.static Pathcopy(Path source, Path target, CopyOption... options)Copy a file to a target file.static PathcreateDirectories(Path dir, FileAttribute... attrs)Creates a directory by creating all nonexistent parent directories first.static PathcreateDirectory(Path dir, FileAttribute... attrs)Creates a new directory.static PathcreateFile(Path path, FileAttribute... attrs)Creates a new and empty file, failing if the file already exists.static PathcreateLink(Path link, Path existing)Creates a new link (directory entry) for an existing file (optional operation).static PathcreateSymbolicLink(Path link, Path target, FileAttribute... attrs)Creates a symbolic link to a target (optional operation).static PathcreateTempDirectory(Path dir, String prefix, FileAttribute... attrs)Creates a new directory in the specified directory, using the given prefix to generate its name.static PathcreateTempDirectory(String prefix, FileAttribute... attrs)Creates a new directory in the default temporary-file directory, using the given prefix to generate its name.static PathcreateTempFile(Path dir, String prefix, String suffix, FileAttribute... attrs)Creates a new empty file in the specified directory, using the given prefix and suffix strings to generate its name.static PathcreateTempFile(String prefix, String suffix, FileAttribute... attrs)Creates an empty file in the default temporary-file directory, using the given prefix and suffix to generate its name.static voiddelete(Path path)Deletes a file.static booleandeleteIfExists(Path path)Deletes a file if it exists.static booleanexists(Path path, LinkOption... options)Tests whether a file exists.static Streamfind(Path start, int maxDepth, BiPredicate matcher, FileVisitOption... options)Return a Stream that is lazily populated with Path by searching for files in a file tree rooted at a given starting file.static ObjectgetAttribute(Path path, String attribute, LinkOption... options)Reads the value of a file attribute.static
VgetFileAttributeView(Path path, Class type, LinkOption... options)Returns a file attribute view of a given type.static FileStoregetFileStore(Path path)Returns the FileStore representing the file store where a file is located.static FileTimegetLastModifiedTime(Path path, LinkOption... options)Returns a file's last modified time.static UserPrincipalgetOwner(Path path, LinkOption... options)Returns the owner of a file.static SetgetPosixFilePermissions(Path path, LinkOption... options)Returns a file's POSIX file permissions.static booleanisDirectory(Path path, LinkOption... options)Tests whether a file is a directory.static booleanisExecutable(Path path)Tests whether a file is executable.static booleanisHidden(Path path)Tells whether or not a file is considered hidden.static booleanisReadable(Path path)Tests whether a file is readable.static booleanisRegularFile(Path path, LinkOption... options)Tests whether a file is a regular file with opaque content.static booleanisSameFile(Path path, Path path2)Tests if two paths locate the same file.static booleanisSymbolicLink(Path path)Tests whether a file is a symbolic link.static booleanisWritable(Path path)Tests whether a file is writable.static Streamlines(Path path)Read all lines from a file as a Stream.static Streamlines(Path path, Charset cs)Read all lines from a file as a Stream.static Streamlist(Path dir)Return a lazily populated Stream, the elements of which are the entries in the directory.static Pathmove(Path source, Path target, CopyOption... options)Move or rename a file to a target file.static BufferedReadernewBufferedReader(Path path)Opens a file for reading, returning a BufferedReader to read text from the file in an efficient manner.static BufferedReadernewBufferedReader(Path path, Charset cs)Opens a file for reading, returning a BufferedReader that may be used to read text from the file in an efficient manner.static BufferedWriternewBufferedWriter(Path path, Charset cs, OpenOption... options)Opens or creates a file for writing, returning a BufferedWriter that may be used to write text to the file in an efficient manner.static BufferedWriternewBufferedWriter(Path path, OpenOption... options)Opens or creates a file for writing, returning a BufferedWriter to write text to the file in an efficient manner.static SeekableByteChannelnewByteChannel(Path path, OpenOption... options)Opens or creates a file, returning a seekable byte channel to access the file.static SeekableByteChannelnewByteChannel(Path path, Set... attrs)Opens or creates a file, returning a seekable byte channel to access the file.static DirectoryStreamnewDirectoryStream(Path dir)Opens a directory, returning a DirectoryStream to iterate over all entries in the directory.static DirectoryStreamnewDirectoryStream(Path dir, DirectoryStream.Filter... attrs) throws IOExceptionOpens or creates a file, returning a seekable byte channel to access the file. The options parameter determines how the file is opened. The READ and WRITE options determine if the file should be opened for reading and/or writing. If neither option (or the APPEND option) is present then the file is opened for reading. By default reading or writing commence at the beginning of the file. In the addition to READ and WRITE, the following options may be present: Option Description APPEND If this option is present then the file is opened for writing and each invocation of the channel's write method first advances the position to the end of the file and then writes the requested data. Whether the advancement of the position and the writing of the data are done in a single atomic operation is system-dependent and therefore unspecified. This option may not be used in conjunction with the READ or TRUNCATE_EXISTING options. TRUNCATE_EXISTING If this option is present then the existing file is truncated to a size of 0 bytes. This option is ignored when the file is opened only for reading. CREATE_NEW If this option is present then a new file is created, failing if the file already exists or is a symbolic link. When creating a file the check for the existence of the file and the creation of the file if it does not exist is atomic with respect to other file system operations. This option is ignored when the file is opened only for reading. CREATE If this option is present then an existing file is opened if it exists, otherwise a new file is created. This option is ignored if the CREATE_NEW option is also present or the file is opened only for reading. DELETE_ON_CLOSE When this option is present then the implementation makes a best effort attempt to delete the file when closed by the close method. If the close method is not invoked then a best effort attempt is made to delete the file when the Java virtual machine terminates. SPARSE When creating a new file this option is a hint that the new file will be sparse. This option is ignored when not creating a new file. SYNC Requires that every update to the file's content or metadata be written synchronously to the underlying storage device. (see Synchronized I/O file integrity). DSYNC Requires that every update to the file's content be written synchronously to the underlying storage device. (see Synchronized I/O file integrity). An implementation may also support additional implementation specific options. The attrs parameter is optional file-attributes to set atomically when a new file is created. In the case of the default provider, the returned seekable byte channel is a FileChannel. Usage Examples: Path path = ... // open file for reading ReadableByteChannel rbc = Files.newByteChannel(path, EnumSet.of(READ))); // open file for writing to the end of an existing file, creating // the file if it doesn't already exist WritableByteChannel wbc = Files.newByteChannel(path, EnumSet.of(CREATE,APPEND)); // create file with initial permissions, opening it for both reading and writing FileAttribute perms = ... SeekableByteChannel sbc = Files.newByteChannel(path, EnumSet.of(CREATE_NEW,READ,WRITE), perms); Parameters:path - the path to the file to open or createoptions - options specifying how the file is openedattrs - an optional list of file attributes to set atomically when creating the fileReturns:a new seekable byte channelThrows:IllegalArgumentException - if the set contains an invalid combination of optionsUnsupportedOperationException - if an unsupported open option is specified or the array contains attributes that cannot be set atomically when creating the fileFileAlreadyExistsException - if a file of that name already exists and the CREATE_NEW option is specified (optional specific exception)IOException - if an I/O error occursSecurityException - In the case of the default provider, and a security manager is installed, the checkRead method is invoked to check read access to the path if the file is opened for reading. The checkWrite method is invoked to check write access to the path if the file is opened for writing. The checkDelete method is invoked to check delete access if the file is opened with the DELETE_ON_CLOSE option.See Also:FileChannel.open(Path,Set,FileAttribute[])newByteChannelpublic static SeekableByteChannel newByteChannel(Path path, OpenOption... options) throws IOExceptionOpens or creates a file, returning a seekable byte channel to access the file. This method opens or creates a file in exactly the manner specified by the newByteChannel method.Parameters:path - the path to the file to open or createoptions - options specifying how the file is openedReturns:a new seekable byte channelThrows:IllegalArgumentException - if the set contains an invalid combination of optionsUnsupportedOperationException - if an unsupported open option is specifiedFileAlreadyExistsException - if a file of that name already exists and the CREATE_NEW option is specified (optional specific exception)IOException - if an I/O error occursSecurityException - In the case of the default provider, and a security manager is installed, the checkRead method is invoked to check read access to the path if the file is opened for reading. The checkWrite method is invoked to check write access to the path if the file is opened for writing. The checkDelete method is invoked to check delete access if the file is opened with the DELETE_ON_CLOSE option.See Also:FileChannel.open(Path,OpenOption[])newDirectoryStreampublic static DirectoryStream newDirectoryStream(Path dir) throws IOExceptionOpens a directory, returning a DirectoryStream to iterate over all entries in the directory. The elements returned by the directory stream's iterator are of type Path, each one representing an entry in the directory. The Path objects are obtained as if by resolving the name of the directory entry against dir. When not using the try-with-resources construct, then directory stream's close method should be invoked after iteration is completed so as to free any resources held for the open directory. When an implementation supports operations on entries in the directory that execute in a race-free manner then the returned directory stream is a SecureDirectoryStream.Parameters:dir - the path to the directoryReturns:a new and open DirectoryStream objectThrows:NotDirectoryException - if the file could not otherwise be opened because it is not a directory (optional specific exception)IOException - if an I/O error occursSecurityException - In the case of the default provider, and a security manager is installed, the checkRead method is invoked to check read access to the directory.newDirectoryStreampublic static DirectoryStream newDirectoryStream(Path dir, String glob) throws IOExceptionOpens a directory, returning a DirectoryStream to iterate over the entries in the directory. The elements returned by the directory stream's iterator are of type Path, each one representing an entry in the directory. The Path objects are obtained as if by resolving the name of the directory entry against dir. The entries returned by the iterator are filtered by matching the String representation of their file names against the given globbing pattern. For example, suppose we want to iterate over the files ending with ".java" in a directory: Path dir = ... try (DirectoryStream stream = Files.newDirectoryStream(dir, "*.java")) : The globbing pattern is specified by the getPathMatcher method. When not using the try-with-resources construct, then directory stream's close method should be invoked after iteration is completed so as to free any resources held for the open directory. When an implementation supports operations on entries in the directory that execute in a race-free manner then the returned directory stream is a SecureDirectoryStream.Parameters:dir - the path to the directoryglob - the glob patternReturns:a new and open DirectoryStream objectThrows:PatternSyntaxException - if the pattern is invalidNotDirectoryException - if the file could not otherwise be opened because it is not a directory (optional specific exception)IOException - if an I/O error occursSecurityException - In the case of the default provider, and a security manager is installed, the checkRead method is invoked to check read access to the directory.newDirectoryStreampublic static DirectoryStream newDirectoryStream(Path dir, DirectoryStream.Filter... attrs) throws IOExceptionCreates a new and empty file, failing if the file already exists. The check for the existence of the file and the creation of the new file if it does not exist are a single operation that is atomic with respect to all other filesystem activities that might affect the directory. The attrs parameter is optional file-attributes to set atomically when creating the file. Each attribute is identified by its name. If more than one attribute of the same name is included in the array then all but the last occurrence is ignored.Parameters:path - the path to the file to createattrs - an optional list of file attributes to set atomically when creating the fileReturns:the fileThrows:UnsupportedOperationException - if the array contains an attribute that cannot be set atomically when creating the fileFileAlreadyExistsException - if a file of that name already exists (optional specific exception)IOException - if an I/O error occurs or the parent directory does not existSecurityException - In the case of the default provider, and a security manager is installed, the checkWrite method is invoked to check write access to the new file.createDirectorypublic static Path createDirectory(Path dir, FileAttribute... attrs) throws IOExceptionCreates a new directory. The check for the existence of the file and the creation of the directory if it does not exist are a single operation that is atomic with respect to all other filesystem activities that might affect the directory. The createDirectories method should be used where it is required to create all nonexistent parent directories first. The attrs parameter is optional file-attributes to set atomically when creating the directory. Each attribute is identified by its name. If more than one attribute of the same name is included in the array then all but the last occurrence is ignored.Parameters:dir - the directory to createattrs - an optional list of file attributes to set atomically when creating the directoryReturns:the directoryThrows:UnsupportedOperationException - if the array contains an attribute that cannot be set atomically when creating the directoryFileAlreadyExistsException - if a directory could not otherwise be created because a file of that name already exists (optional specific exception)IOException - if an I/O error occurs or the parent directory does not existSecurityException - In the case of the default provider, and a security manager is installed, the checkWrite method is invoked to check write access to the new directory.createDirectoriespublic static Path createDirectories(Path dir, FileAttribute... attrs) throws IOExceptionCreates a directory by creating all nonexistent parent directories first. Unlike the createDirectory method, an exception is not thrown if the directory could not be created because it already exists. The attrs parameter is optional file-attributes to set atomically when creating the nonexistent directories. Each file attribute is identified by its name. If more than one attribute of the same name is included in the array then all but the last occurrence is ignored. If this method fails, then it may do so after creating some, but not all, of the parent directories.Parameters:dir - the directory to createattrs - an optional list of file attributes to set atomically when creating the directoryReturns:the directoryThrows:UnsupportedOperationException - if the array contains an attribute that cannot be set atomically when creating the directoryFileAlreadyExistsException - if dir exists but is not a directory (optional specific exception)IOException - if an I/O error occursSecurityException - in the case of the default provider, and a security manager is installed, the checkWrite method is invoked prior to attempting to create a directory and its checkRead is invoked for each parent directory that is checked. If dir is not an absolute path then its toAbsolutePath may need to be invoked to get its absolute path. This may invoke the security manager's checkPropertyAccess method to check access to the system property user.dircreateTempFilepublic static Path createTempFile(Path dir, String prefix, String suffix, FileAttribute... attrs) throws IOExceptionCreates a new empty file in the specified directory, using the given prefix and suffix strings to generate its name. The resulting Path is associated with the same FileSystem as the given directory. The details as to how the name of the file is constructed is implementation dependent and therefore not specified. Where possible the prefix and suffix are used to construct candidate names in the same manner as the File.createTempFile(String,String,File) method. As with the File.createTempFile methods, this method is only part of a temporary-file facility. Where used as a work files, the resulting file may be opened using the DELETE_ON_CLOSE option so that the file is deleted when the appropriate close method is invoked. Alternatively, a shutdown-hook, or the File.deleteOnExit() mechanism may be used to delete the file automatically. The attrs parameter is optional file-attributes to set atomically when creating the file. Each attribute is identified by its name. If more than one attribute of the same name is included in the array then all but the last occurrence is ignored. When no file attributes are specified, then the resulting file may have more restrictive access permissions to files created by the File.createTempFile(String,String,File) method.Parameters:dir - the path to directory in which to create the fileprefix - the prefix string to be used in generating the file's name; may be nullsuffix - the suffix string to be used in generating the file's name; may be null, in which case ".tmp" is usedattrs - an optional list of file attributes to set atomically when creating the fileReturns:the path to the newly created file that did not exist before this method was invokedThrows:IllegalArgumentException - if the prefix or suffix parameters cannot be used to generate a candidate file nameUnsupportedOperationException - if the array contains an attribute that cannot be set atomically when creating the directoryIOException - if an I/O error occurs or dir does not existSecurityException - In the case of the default provider, and a security manager is installed, the checkWrite method is invoked to check write access to the file.createTempFilepublic static Path createTempFile(String prefix, String suffix, FileAttribute... attrs) throws IOExceptionCreates an empty file in the default temporary-file directory, using the given prefix and suffix to generate its name. The resulting Path is associated with the default FileSystem. This method works in exactly the manner specified by the createTempFile(Path,String,String,FileAttribute[]) method for the case that the dir parameter is the temporary-file directory.Parameters:prefix - the prefix string to be used in generating the file's name; may be nullsuffix - the suffix string to be used in generating the file's name; may be null, in which case ".tmp" is usedattrs - an optional list of file attributes to set atomically when creating the fileReturns:the path to the newly created file that did not exist before this method was invokedThrows:IllegalArgumentException - if the prefix or suffix parameters cannot be used to generate a candidate file nameUnsupportedOperationException - if the array contains an attribute that cannot be set atomically when creating the directoryIOException - if an I/O error occurs or the temporary-file directory does not existSecurityException - In the case of the default provider, and a security manager is installed, the checkWrite method is invoked to check write access to the file.createTempDirectorypublic static Path createTempDirectory(Path dir, String prefix, FileAttribute... attrs) throws IOExceptionCreates a new directory in the specified directory, using the given prefix to generate its name. The resulting Path is associated with the same FileSystem as the given directory. The details as to how the name of the directory is constructed is implementation dependent and therefore not specified. Where possible the prefix is used to construct candidate names. As with the createTempFile methods, this method is only part of a temporary-file facility. A shutdown-hook, or the File.deleteOnExit() mechanism may be used to delete the directory automatically. The attrs parameter is optional file-attributes to set atomically when creating the directory. Each attribute is identified by its name. If more than one attribute of the same name is included in the array then all but the last occurrence is ignored.Parameters:dir - the path to directory in which to create the directoryprefix - the prefix string to be used in generating the directory's name; may be nullattrs - an optional list of file attributes to set atomically when creating the directoryReturns:the path to the newly created directory that did not exist before this method was invokedThrows:IllegalArgumentException - if the prefix cannot be used to generate a candidate directory nameUnsupportedOperationException - if the array contains an attribute that cannot be set atomically when creating the directoryIOException - if an I/O error occurs or dir does not existSecurityException - In the case of the default provider, and a security manager is installed, the checkWrite method is invoked to check write access when creating the directory.createTempDirectorypublic static Path createTempDirectory(String prefix, FileAttribute... attrs) throws IOExceptionCreates a new directory in the default temporary-file directory, using the given prefix to generate its name. The resulting Path is associated with the default FileSystem. This method works in exactly the manner specified by createTempDirectory(Path,String,FileAttribute[]) method for the case that the dir parameter is the temporary-file directory.Parameters:prefix - the prefix string to be used in generating the directory's name; may be nullattrs - an optional list of file attributes to set atomically when creating the directoryReturns:the path to the newly created directory that did not exist before this method was invokedThrows:IllegalArgumentException - if the prefix cannot be used to generate a candidate directory nameUnsupportedOperationException - if the array contains an attribute that cannot be set atomically when creating the directoryIOException - if an I/O error occurs or the temporary-file directory does not existSecurityException - In the case of the default provider, and a security manager is installed, the checkWrite method is invoked to check write access when creating the directory.createSymbolicLinkpublic static Path createSymbolicLink(Path link, Path target, FileAttribute... attrs) throws IOExceptionCreates a symbolic link to a target (optional operation). The target parameter is the target of the link. It may be an absolute or relative path and may not exist. When the target is a relative path then file system operations on the resulting link are relative to the path of the link. The attrs parameter is optional attributes to set atomically when creating the link. Each attribute is identified by its name. If more than one attribute of the same name is included in the array then all but the last occurrence is ignored. Where symbolic links are supported, but the underlying FileStore does not support symbolic links, then this may fail with an IOException. Additionally, some operating systems may require that the Java virtual machine be started with implementation specific privileges to create symbolic links, in which case this method may throw IOException.Parameters:link - the path of the symbolic link to createtarget - the target of the symbolic linkattrs - the array of attributes to set atomically when creating the symbolic linkReturns:the path to the symbolic linkThrows:UnsupportedOperationException - if the implementation does not support symbolic links or the array contains an attribute that cannot be set atomically when creating the symbolic linkFileAlreadyExistsException - if a file with the name already exists (optional specific exception)IOException - if an I/O error occursSecurityException - In the case of the default provider, and a security manager is installed, it denies LinkPermission("symbolic") or its checkWrite method denies write access to the path of the symbolic link.createLinkpublic static Path createLink(Path link, Path existing) throws IOExceptionCreates a new link (directory entry) for an existing file (optional operation). The link parameter locates the directory entry to create. The existing parameter is the path to an existing file. This method creates a new directory entry for the file so that it can be accessed using link as the path. On some file systems this is known as creating a "hard link". Whether the file attributes are maintained for the file or for each directory entry is file system specific and therefore not specified. Typically, a file system requires that all links (directory entries) for a file be on the same file system. Furthermore, on some platforms, the Java virtual machine may require to be started with implementation specific privileges to create hard links or to create links to directories.Parameters:link - the link (directory entry) to createexisting - a path to an existing fileReturns:the path to the link (directory entry)Throws:UnsupportedOperationException - if the implementation does not support adding an existing file to a directoryFileAlreadyExistsException - if the entry could not otherwise be created because a file of that name already exists (optional specific exception)IOException - if an I/O error occursSecurityException - In the case of the default provider, and a security manager is installed, it denies LinkPermission("hard") or its checkWrite method denies write access to either the link or the existing file.deletepublic static void delete(Path path) throws IOExceptionDeletes a file. An implementation may require to examine the file to determine if the file is a directory. Consequently this method may not be atomic with respect to other file system operations. If the file is a symbolic link then the symbolic link itself, not the final target of the link, is deleted. If the file is a directory then the directory must be empty. In some implementations a directory has entries for special files or links that are created when the directory is created. In such implementations a directory is considered empty when only the special entries exist. This method can be used with the walkFileTree method to delete a directory and all entries in the directory, or an entire file-tree where required. On some operating systems it may not be possible to remove a file when it is open and in use by this Java virtual machine or other programs.Parameters:path - the path to the file to deleteThrows:NoSuchFileException - if the file does not exist (optional specific exception)DirectoryNotEmptyException - if the file is a directory and could not otherwise be deleted because the directory is not empty (optional specific exception)IOException - if an I/O error occursSecurityException - In the case of the default provider, and a security manager is installed, the SecurityManager.checkDelete(String) method is invoked to check delete access to the filedeleteIfExistspublic static boolean deleteIfExists(Path path) throws IOExceptionDeletes a file if it exists. As with the delete(Path) method, an implementation may need to examine the file to determine if the file is a directory. Consequently this method may not be atomic with respect to other file system operations. If the file is a symbolic link, then the symbolic link itself, not the final target of the link, is deleted. If the file is a directory then the directory must be empty. In some implementations a directory has entries for special files or links that are created when the directory is created. In such implementations a director

Reply all
Reply to author
Forward
0 new messages