Nov 24

Often you need to read a file line by line. Alternatively sometimes you want to read text word by word (for example to count the occurrence of different words). The Scanner classes next() method can be used for this as shown in the following example.

		Scanner input = new Scanner(file);  
		while(input.hasNext()) {
			String word = input.next();
		}

written by objects \\ tags: , , , ,

Oct 03

The Desktop class was added in Java 6 to handle launching associated applications on the native desktop.

Following shows how to print a file with the associated native printing facility.

File file = new File("/tmp/file.txt");
Desktop desktop = Desktop.getDesktop();
desktop.print(file);

written by objects \\ tags: , , , ,

Oct 03

The Desktop class was added in Java 6 to handle launching associated applications on the native desktop.

Following shows how to launch the associated application to open a file.

File file = new File("/tmp/file.txt");
Desktop desktop = Desktop.getDesktop();
desktop.open(file);

written by objects \\ tags: , , ,