Deprecated: Assigning the return value of new by reference is deprecated in /home/w3hja33/public_html/wp-includes/cache.php on line 99

Deprecated: Assigning the return value of new by reference is deprecated in /home/w3hja33/public_html/wp-includes/query.php on line 21

Deprecated: Assigning the return value of new by reference is deprecated in /home/w3hja33/public_html/wp-includes/theme.php on line 576
Feature | w3hJava

w3hJava

What, Why, When and How of Java, JavaFX and related technologies


Published September 1st, 2008

File Read Only in JDK6

This is a good feature for all those developer who do a lot of file reading, writing stuff. Java SE 6.0 gives us the feature to set file read only. There are lot of place where its correct and valid to set file as read only rather than leaving it read-write. Like you are writing some version repository or some file that should not be changed.

Here is a small code to change the file read mode:

import java.io.File;
import java.io.IOException;

public class FileReadOnly {

public static void main(String[] args) throws IOException {

File file = new File(”test.txt”);

file.createNewFile();
System.out.println(”Before. canWrite?” + file.canWrite());

file.setWritable(false);
System.out.println(”After. canWrite?” + file.canWrite());
}
}

So, from next time don’t forget to use this.

Published June 21st, 2008

How to use JDK 6 to solve memory issues?

Take care of disk space when you are writing a big program :). Use JDK 6 features:

import java.io.File;

public class DiskSpaceCheck {
public DiskSpaceCheck() {
File file = new File("E:");
System.out.println("E:");
System.out.println("Total:  " + file.getTotalSpace());
System.out.println("Free:   " + file.getFreeSpace());
System.out.println("Usable: " + file.getUsableSpace());

file = new File("E://movie");
System.out.println("E://movie");
System.out.println("Total:  " + file.getTotalSpace());
System.out.println("Free:   " + file.getFreeSpace());
System.out.println("Usable: " + file.getUsableSpace());

file = new File("/");
System.out.println("n/");
System.out.println("Total:  " + file.getTotalSpace());
System.out.println("Free:   " + file.getFreeSpace());
System.out.println("Usable: " + file.getUsableSpace());
}

public static void main(String[] args) {
new DiskSpaceCheck();
}
}

I was actually very suprised that why this feature came so late.