: Jaya Hangal's Weblog




« November 2009
SunMonTueWedThuFriSat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
     
       
Today

FEEDS

SEARCH



LINKS




CONTACT
jaya_hangal
Template by
Helquin

Thursday Feb 16, 2006

Check out what Mustang offers in the I/O libraries Mustang-Core-Libraries

Mustang-Core-Libraries

Mustang release has small but very useful enhancements in the core libraries area.
Here is a brief look at  some of them in the I/O area that you must have heard about during the  JavaOne 2005 talk given by Mark Reinhold.

Free Diskspace:

One can now discover the amount of disk space left in the partition named by
the given file. This is one of the highly voted RFE (697 votes). This is a very
handy feature, for example, installers can now determine beforehand
how much diskspace is available on a partition that it's going to install the stuff on.

Three new methods have been added to java.io.File class:

     getFreeSpace()
     getUsableSpace()
     
getTotalSpace()

Using these methods one can do something like:

import java.io.*;
    :
    :
    :
  File dir;
  System.out.println("Total MB     Free    Usable");
 System.out.format(" %6d    %6d   %6d\n",
        (dir.getTotalSpace() >> 20),
        (dir.getFreeSpace() >> 20),
        (dir.getUsableSpace() >> 20));



Changing File Attributes:

In Mustang the java.io.File API provides access to the file attributes for changing its readability, ability to write and ability to make it executable. Check out the following methods for playing around with file attributes:

Changing readability:                            owner-only, owner or everybody
Making it writable or read-only:              owner-only, owner or everybody
Making it executable or not executable: owner-only, owner or everybody

 

Password Prompting:

This is one of the highly voted RFE (438 votes) as well, that fixed the good old problem of password input being echoed on a system console. This is useful for command line tools that accept password from system console, eg: keytool.

The new class  java.io.Console enables reading the password from the console
without echoing it. Here is a small code snipped that shows this:

import java.io.*;
    :
    :
    Console cons;
    char[] passwd = null;
    if ((cons = System.console()) != null)
        passwd = cons.readPassword("[%s]", "Password:");
          :
          :




Comments:

There is also an article on java.sun.com with more information about some of these methods: http://java.sun.com/developer/technicalArticles/J2SE/Desktop/mustang/enhancements/

Posted by 192.18.42.10 on February 16, 2006 at 08:49 AM PST #

Post a Comment:
Comments are closed for this entry.