JDK-7006126 : (fs) Updates to file system API (1/2011)
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 7
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2010-12-10
  • Updated: 2017-05-16
  • Resolved: 2011-03-08
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7 b130Fixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Description
The JSR-203 file sytsem API has been in JDK 7 for a long time. A number of issues and changes have been accumulated and these need to be integrated into JDK 7. 

The main update is to consolidate the file operations into Files to avoid confusion as to whether to add new file operations to Path, Files or Attributes. The Attributes class can be removed.

In addition we have:

1. Files requires a number of utility methods to make it quick and easy to do simple things:
      BufferedReader newBufferedReader(Path,Charset)
      BufferedWriter newBufferedWriter(Path,Charset,OpenOption...)
      byte[] readAllBytes(Path)
      List<String> readAllLines(Path, Charset) 
      long copy(InputStream, Path, CopyOption...)
      long copy(Path, OutputStream)
      Path write(Path, byte[], OpenOption...)
      Path write(Path, Iterable<? extends CharSequence>, Charset, OpenOption...)

2. The checkAccess method is hard to use and should be made available as simple isReadable,
   isWritable, and isExecutable methods. 

3. The API requires simple methods to test the file type, namely isDirectory, isRegularFile,
   isSymbolicLink to avoiding needing to use readAttributes

4. The exists and notExists method need a LinkOption[] parameter so that they can be used 
   without following symbolic links.

5. The new createTempFile method added to java.io.File should be moved to Files and 
   createTempDirecory methods added.

6. Paths.get(String) and FileSystem.getPath should be updated to use var-args so make it 
   easy to join directory and file names.

7. Path requires a few updates:
   - with the file operations moved to Files, and extension methods potentially coming in jdk8, 
     then we shuold consider changing it to an interface.
   - getName() should be renamed to getFileName() to avoid confusing it with getName(int) and/or
     expecting it to return a String
   - we should add startsWith(String) and endsWith(String) to complement the existing methods
   - a resolveSibling method should be added as it very common to want to "replace" the file
     name component
   - normalize and relativize should return the empty path rather than null

8. FileSystems.newFileSystem(FileRef,Map,ClassLoader) does not need the Map (env) parameter.

9. For JDK7 we don't need FileStoreSpaceAttributes and it would be simpler to just have
   FileStore define methods to return the space information.

10. The createFile and createDirectory methods need to be clear that they do not create 
    missing parent directories.

11. The newOutputStream and newByteChannel methods need to make it clear that the security 
    manager's checkDelete method is invoked if the DELETE_ON_CLOSE option is specified.

12. The copy/move methods should suggest that DirectoryNotEmptyException be thrown if 
    REPLACE_EXISTING is specified and the target is a non-empty direcory.

Comments
EVALUATION Need to sync up jdk7 with updates listed in description.
28-01-2011