/** * Renames the file denoted by this abstract pathname. * * <p>Whether or not this method can move a file from one filesystem to another is * platform-dependent. The return value should always be checked to make sure that the rename * operation was successful. * * @param dest The new abstract pathname for the named file * @throws IllegalArgumentException If parameter <code>dest</code> is not a <code>GeneralFile * </code>. * @throws NullPointerException - If dest is null */ public boolean renameTo(GeneralFile dest) throws IllegalArgumentException, NullPointerException { try { if (dest instanceof FTPFile) { if (ftpClient.equals(((FTPFile) dest).ftpClient)) { ftpClient.rename(getPath(), dest.getPath()); } else { // TODO some ftp to ftp copy... if (!dest.exists()) { copyTo(dest); delete(); } else return false; } } else { if (!dest.exists()) { copyTo(dest); delete(); } else return false; } } catch (IOException e) { return false; } catch (FTPException e) { return false; } return true; }
protected void open(GeneralFile file) throws IOException { if (!file.exists()) { file.createNewFile(); } else if (file.isDirectory()) { throw new IllegalArgumentException("Wrong permissions or " + file + " is a directory"); } wrapper = new RandomAccessFile(file.getAbsolutePath(), mode); }