// Create from a given File
 private void initRead(File f) {
   try {
     initRead(f.getCanonicalPath());
   } catch (Exception e) {
     throw new ResourceException("FileResource: cannot access " + f);
   }
 }
 /**
  * Create a <code>FileResource</code> object that opens a file whose name is passed as a
  * parameter, possibly to write to it.
  *
  * <p>If the user wants to change the contents of the open file by using the method <code>write
  * </code> to add new strings to it, pass <code>true</code> as the second parameter. Otherwise it
  * is assumed the user will only iterate over the existing contents of the file.
  *
  * <p>The named file should be on the current class path to be found.
  *
  * @param filename the name of the file to be opened
  * @param writable allow changes to this file only if true
  * @throws exception if the filename cannot be accessed
  */
 public FileResource(String filename, boolean writable) {
   if (writable) {
     initWrite(filename);
   } else {
     initRead(filename);
   }
 }
 /**
  * Create a <code>FileResource</code> object that opens a file represented by the File object
  * passed as a parameter, possibly to write to it.
  *
  * <p>If the user wants to change the contents of the open file by using the method <code>write
  * </code> to add new strings to it, pass <code>true</code> as the second parameter. Otherwise it
  * is assumed the user will only iterate over the existing contents of the file.
  *
  * <p>Useful, for example, when used in conjunction with the <code>DirectoryResource</code> class.
  *
  * @param file the file to be represented by this resource
  * @param writable allow changes to this file only if true
  * @throws exception if the file cannot be accessed
  */
 public FileResource(File file, boolean writable) {
   if (writable) {
     initWrite(file);
   } else {
     initRead(file);
   }
 }
 /**
  * Create a <code>FileResource</code> object that opens the file chosen by the user using a file
  * selection dialog box, possibly to write to it.
  *
  * <p>If the user wants to change the contents of the open file by using the method <code>write
  * </code> to add new strings to it, pass <code>true</code> as the second parameter. Otherwise it
  * is assumed the user will only iterate over the existing contents of the file.
  *
  * @param writable allow changes to this file only if true
  * @throws exception if no file is selected by the user
  */
 public FileResource(boolean writable) {
   if (writable) {
     initWrite();
   } else {
     initRead();
   }
 }
 // Prompt user for file to open
 private void initRead() {
   File f = FileSelector.selectFile();
   if (f == null) {
     throw new ResourceException("FileResource: no file choosen for reading");
   } else {
     initRead(f);
   }
 }
 // create file for writing
 private void initWrite(File f) {
   try {
     mySaveFile = f;
     if (f.exists() && f.canWrite()) {
       initRead(f);
     } else {
       mySource = "";
       myPath = f.getCanonicalPath();
     }
   } catch (Exception e) {
     throw new ResourceException("FileResource: cannot access " + f, e);
   }
 }
 /**
  * Create a <code>FileResource</code> object that opens a file whose name is passed as a
  * parameter.
  *
  * <p>The named file should be on the current class path to be found.
  *
  * @param filename the name of the file to be opened
  * @throws exception if the filename cannot be accessed
  */
 public FileResource(String filename) {
   initRead(filename);
 }
 /**
  * Create a <code>FileResource</code> object that opens a file represented by the File object
  * passed as a parameter.
  *
  * <p>Useful, for example, when used in conjunction with the <code>DirectoryResource</code> class.
  *
  * @param file the file to be represented by this resource
  * @throws exception if the file cannot be accessed
  */
 public FileResource(File file) {
   initRead(file);
 }
 /**
  * Create a <code>FileResource</code> object that opens the file chosen by the user using a file
  * selection dialog box.
  *
  * @throws exception if no file is selected by the user
  */
 public FileResource() {
   initRead();
 }