Sebastian Rittau's Blog

Tuesday
Jan 02 2007

Java File API

Java, Programming

I don't like Java's File API. It's main problem is that is mixes several responsibilities into one class. One responsibility is handling of "abstract" file and path names, i.e. operating system independent file names. The other responsibilities are all file system related: Querying file meta information (access rights, access times, file type), creating files, and listing directory contents. In my opinion these should be clearly separated.

I am also missing a constructor or construction method that creates a File instance from a list of path components like this:

  File f = new File("/", "path", "to", "file");

Maybe I should start a Java warts page, similar to my Python warts page ...

Comments

I agree

by Canuck

I am learning Java, but I got very disappointed when I realized I had to call so many functions to open a file. Heck, even C does it easier (remember fopen?).

That's a turnoff for me. I'd rather learn C++, at least I won't require JRE installed on the target computer...