Java SE 6.0 new feature Experience

Source: Internet
Author: User
Tags file system readable java se

Mustang (also known as Java SE 6) is now entering its second Test phase. The author of this article will discuss with you further the many new features provided in this new release (from console I/O and access control methods to system tray APIs and table sorting and filtering, etc.).

First, the introduction

Mustang (also known as Java SE 6) is now entering its second Test phase. In this article, let's explore the many new features offered in this new release (from console I/O and access control methods to system tray APIs and table sorting and filtering, etc.).

After analyzing several new file methods that control file and directory access permissions, this article will show you the new desktop Integration API. Then, the paper also analyzes the ability of Mustang's new programming access network parameters. Finally, this article will discuss the new sorting and filtering capabilities of the table components.

"Note" I developed and tested the Java sample application for this article using the second beta version of Java SE 6 (build 86), the OS platform is Windows? SE.

Control method of Access permission

In some ways, an instance of the file class is actually an abstract pathname that identifies a file or directory object in the file system. File systems can restrict the read, write, and execute operations that are implemented on this object.

Read, write, and execute restrictions are collectively referred to as "access permissions." The file system can associate multiple access rights collections to a single object. For example, a collection can be used for the owner of an object and another collection can be used for all other users.

The access rights provided in the previous version may cause some methods of the file class to fail when used directly for accessing the object. For this reason, Mustang introduces six new methods for the file class to allow you to modify the access rights of the pathname:

① "Public boolean setexecutable (Boolean executable, Boolean owneronly)": Sets the execution permission of the owner or each person for the specified abstract path name. An action is allowed when executable is true, and when the value passed to it is false, execution is not allowed. Passing true to the parameter owneronly only allows the owner of the abstract pathname to have the license, and when Owneronly is false, the license is granted to everyone. If the underlying file system cannot differentiate between the owner's execution license and everyone's execution license, the license applies to everyone, regardless of the owneronly value.

The method returns true on success, otherwise it returns false. The method call fails if the user does not have permission to change the access rights of the abstract pathname or if the underlying file system does not implement a permission to execute and executable is false.

② "Public boolean setexecutable (Boolean executable)": This method makes it easy to set the owner's execution permissions for a given abstract pathname.

③public Oolean setreadable (Oolean readable, Oolean owneronly) ": Sets the Read permission for the owner or everyone for this abstract pathname. A read operation is allowed if the parameter readable is true; When the parameter owneronly is true, only the owner of the abstract pathname is allowed to do so, and when Owneronly is false, the license is granted to everyone. If the underlying file system cannot differentiate between the owner's read license and everyone's Read permission, the license applies to everyone, regardless of the owneronly value.

The method returns true on success, otherwise it returns false. The method call fails if the user does not have permission to change the access rights of the abstract pathname or if the underlying file system does not implement a read license and readable is false.

④ "Public boolean setreadable (Boolean readable)": This method makes it easy to set the owner's read permission for a given abstract pathname.

⑤ "Public boolean setwritable (Boolean Writable,boolean owneronly)": Sets the Write permission for the owner or each person for this abstract path name. Write operation is allowed when parameter writable is true; When the parameter owneronly is true, only the owner of the abstract pathname is allowed to do so, and when Owneronly is false, the license is granted to everyone. If the underlying file system cannot differentiate between the owner's write permission and everyone's write permission, the license applies to everyone, regardless of the owneronly value.

This method returns True if the method succeeds, or false. If the user does not have permission to change the access rights of the abstract pathname, the method call fails.

⑥ "Public boolean setwritable (Boolean writable)": This method makes it easy to set the owner's write permission for a given abstract pathname.

"Note" If a security manager exists and its "public void Checkwrite (String file)" method does not allow write operations on a file, each of the methods listed above throws a SecurityException exception.

The file class also provides the following methods to help you get the read, write, and Execute permissions currently set by an object:

①public boolean canRead ();

②public boolean canwrite ();

③public boolean CanExecute () (newly introduced in Mustang).

I created a simple application named Writabledemo that shows the usage of setwritable () and CanWrite () methods. In this application, you can make a file system object writable or read-only, and can also view the current settings for this license. The example in the source code of this article 1 shows this file Writabledemo.java (slightly).

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.