Skip to main content

Update pre-JDK7 APIs to support java.nio.file.Path?

2 replies [Last post]
Anonymous

Should some of the JDK 7 APIs with constructors and methods that accept a java.util.File or a String (representing a path) also be updated to accept a java.nio.file.Path?

This is a minor annoyance, but adding additional overloaded methods accepting a
Path would cut down on having to type "some_path.toString()" wherever a String representation of a path is expected.

Examples:
Path path = ... // some path to a file on the file system
new FileInputStream(path.toString());
new FileOutputStream(path.toString());

I'm not sure what kind of impact (good or bad) this suggestion would have, but I thought I'd bring this up as I noticed the somewhat annoying "toString()" showing up in my code.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
alanb
Offline
Joined: 2005-08-08
Points: 0

In the above, then just do path.newInputStream() or path.newOutputStream(). No need to convert to String. In general, it's best to avoid converting to String if you can.

fudmail

Prefect. That makes sense. Thanks for the response.