This example demonstrates how to use the Scrapbook to run a fragment of code for testing or experimental purposes.
String selectedName; String initialDirectory="C:"; java.awt.FileDialog anOpener; anOpener=new java.awt.FileDialog(new java.awt.Frame(), "Check file access rights", 0); anOpener.setDirectory(initialDirectory); anOpener.show(); selectedName = anOpener.getDirectory()+anOpener.getFile(); java.io.File checkFile = new java.io.File(selectedName); if (checkFile.canWrite()) { System.out.println("You have write-access to " + selectedName+"."); } else System.out.println("You have read-only access to " + selectedName+"."); return checkFile;
The Console will output a message indicating whether you have write access or read-only access to the selected file.
Organizing Your Ideas in the Scrapbook
Experimenting with Code Fragments