Miscellaneous tips

Making your applet "beep"

To make your applet cause a "beep" on the console, try using

Toolkit.getDefaultToolkit().beep()

It creates a very convenient way of easily creating that "beep" sound!

Sun.* packages

Java software will only support the java.* packages, and not the sun.* packages. So developers should try to avoid using the sun.* packages.

Launching external document handler applications

To launch documents using the appropriate application in Windows NT, use the code

String doc = "c:\\My Documents\mydocument.doc";

Runtime.getRuntime().exec("CMD.EXE /C " + doc);

Windows NT uses the document's MIME type to accomplish this.

Spaces, filenames, and Runtime

Using filenames that contain spaces as arguments to Runtime.exec() can be problematic, as it parses the arguments using the spaces as delimiters, regardless of quotes. To get around this, consider using the following snippet:

String[] cmd = {"cat", "my document.txt"};

Runtime.getRuntime().Exec(cmd);

This tokenizes the arguments before Runtime receives them.

Making documents read-only

To protect a Java-created document (and already-existing ones, provided permissions are correct), developers can make it read-only. That code would look like:

File file = new File ("/tmp/myFile.txt");

file.setReadOnly();

Hosted by www.Geocities.ws

1