O'Reilly logo

Python Programming with the Java™ Class Libraries: A Tutorial for Building Web and Enterprise Applications with Jython by Richard Hightower

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The File Class

The Java File class is nothing like the Python file object, in spite of the name. It allows you to check the following attributes of a file:

  • Read

  • Write

  • Size

  • Last modification date

  • Directory or not a directory

It also provides the methods listed below to view a directory's contents, to create and delete directories, and to delete directory files:

  • canRead()— determines permission and access to read the file

  • canWrite()— determines read-only or read/write access

  • delete()— deletes the current file referenced by this file object

  • equals(File)— determines if the file referenced by this object is the same as the argument

  • exists()— determines if the file exists

  • getPath()— gets the file path (can be relative)

  • getAbsolutePath()— same as above, but resolves ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required