⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fileutils.java

📁 Use the links below to download a source distribution of Ant from one of our mirrors. It is good pra
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
     */    public void copyFile(File sourceFile, File destFile) throws IOException {        copyFile(sourceFile, destFile, null, false, false);    }    /**     * Convenience method to copy a file from a source to a destination     * specifying if token filtering must be used.     *     * @param sourceFile the file to copy from.     *                   Must not be <code>null</code>.     * @param destFile the file to copy to.     *                 Must not be <code>null</code>.     * @param filters the collection of filters to apply to this copy.     *     * @throws IOException if the copying fails.     */    public void copyFile(File sourceFile, File destFile, FilterSetCollection filters)            throws IOException {        copyFile(sourceFile, destFile, filters, false, false);    }    /**     * Convenience method to copy a file from a source to a     * destination specifying if token filtering must be used and if     * source files may overwrite newer destination files.     *     * @param sourceFile the file to copy from.     *                   Must not be <code>null</code>.     * @param destFile the file to copy to.     *                 Must not be <code>null</code>.     * @param filters the collection of filters to apply to this copy.     * @param overwrite Whether or not the destination file should be     *                  overwritten if it already exists.     *     * @throws IOException if the copying fails.     */    public void copyFile(File sourceFile, File destFile, FilterSetCollection filters,                         boolean overwrite) throws IOException {        copyFile(sourceFile, destFile, filters, overwrite, false);    }    /**     * Convenience method to copy a file from a source to a     * destination specifying if token filtering must be used, if     * source files may overwrite newer destination files and the     * last modified time of <code>destFile</code> file should be made equal     * to the last modified time of <code>sourceFile</code>.     *     * @param sourceFile the file to copy from.     *                   Must not be <code>null</code>.     * @param destFile the file to copy to.     *                 Must not be <code>null</code>.     * @param filters the collection of filters to apply to this copy.     * @param overwrite Whether or not the destination file should be     *                  overwritten if it already exists.     * @param preserveLastModified Whether or not the last modified time of     *                             the resulting file should be set to that     *                             of the source file.     *     * @throws IOException if the copying fails.     */    public void copyFile(File sourceFile, File destFile, FilterSetCollection filters,                         boolean overwrite, boolean preserveLastModified) throws IOException {        copyFile(sourceFile, destFile, filters, overwrite, preserveLastModified, null);    }    /**     * Convenience method to copy a file from a source to a destination specifying if token     * filtering must be used, if source files may overwrite newer destination files, the last     * modified time of <code>destFile</code> file should be made equal to the last modified time     * of <code>sourceFile</code> and which character encoding to assume.     *     * @param sourceFile the file to copy from. Must not be <code>null</code>.     * @param destFile the file to copy to. Must not be <code>null</code>.     * @param filters the collection of filters to apply to this copy.     * @param overwrite Whether or not the destination file should be overwritten if it already     *            exists.     * @param preserveLastModified Whether or not the last modified time of the resulting file     *            should be set to that of the source file.     * @param encoding the encoding used to read and write the files.     *     * @throws IOException if the copying fails.     *     * @since Ant 1.5     */    public void copyFile(File sourceFile, File destFile,                         FilterSetCollection filters, boolean overwrite,                         boolean preserveLastModified, String encoding) throws IOException {        copyFile(sourceFile, destFile, filters, null, overwrite,                 preserveLastModified, encoding, null);    }    /**     * Convenience method to copy a file from a source to a     * destination specifying if token filtering must be used, if     * filter chains must be used, if source files may overwrite     * newer destination files and the last modified time of     * <code>destFile</code> file should be made equal     * to the last modified time of <code>sourceFile</code>.     *     * @param sourceFile the file to copy from.     *                   Must not be <code>null</code>.     * @param destFile the file to copy to.     *                 Must not be <code>null</code>.     * @param filters the collection of filters to apply to this copy.     * @param filterChains filterChains to apply during the copy.     * @param overwrite Whether or not the destination file should be     *                  overwritten if it already exists.     * @param preserveLastModified Whether or not the last modified time of     *                             the resulting file should be set to that     *                             of the source file.     * @param encoding the encoding used to read and write the files.     * @param project the project instance.     *     * @throws IOException if the copying fails.     *     * @since Ant 1.5     */    public void copyFile(File sourceFile, File destFile,                         FilterSetCollection filters, Vector filterChains,                         boolean overwrite, boolean preserveLastModified,                         String encoding, Project project) throws IOException {        copyFile(sourceFile, destFile, filters, filterChains,                 overwrite, preserveLastModified, encoding, encoding, project);    }    /**     * Convenience method to copy a file from a source to a     * destination specifying if token filtering must be used, if     * filter chains must be used, if source files may overwrite     * newer destination files and the last modified time of     * <code>destFile</code> file should be made equal     * to the last modified time of <code>sourceFile</code>.     *     * @param sourceFile the file to copy from.     *                   Must not be <code>null</code>.     * @param destFile the file to copy to.     *                 Must not be <code>null</code>.     * @param filters the collection of filters to apply to this copy.     * @param filterChains filterChains to apply during the copy.     * @param overwrite Whether or not the destination file should be     *                  overwritten if it already exists.     * @param preserveLastModified Whether or not the last modified time of     *                             the resulting file should be set to that     *                             of the source file.     * @param inputEncoding the encoding used to read the files.     * @param outputEncoding the encoding used to write the files.     * @param project the project instance.     *     *     * @throws IOException if the copying fails.     *     * @since Ant 1.6     */    public void copyFile(File sourceFile, File destFile,                         FilterSetCollection filters, Vector filterChains,                         boolean overwrite, boolean preserveLastModified,                         String inputEncoding, String outputEncoding,                         Project project) throws IOException {        ResourceUtils.copyResource(            new FileResource(sourceFile), new FileResource(destFile),            filters, filterChains, overwrite, preserveLastModified,            inputEncoding, outputEncoding, project);    }    // CheckStyle:ParameterNumberCheck ON    /**     * Calls File.setLastModified(long time). Originally written to     * to dynamically bind to that call on Java1.2+.     *     * @param file the file whose modified time is to be set     * @param time the time to which the last modified time is to be set.     *             if this is -1, the current time is used.     */    public void setFileLastModified(File file, long time) {        ResourceUtils.setLastModified(new FileResource(file), time);    }    /**     * Interpret the filename as a file relative to the given file     * unless the filename already represents an absolute filename.     * Differs from <code>new File(file, filename)</code> in that     * the resulting File's path will always be a normalized,     * absolute pathname.  Also, if it is determined that     * <code>filename</code> is context-relative, <code>file</code>     * will be discarded and the reference will be resolved using     * available context/state information about the filesystem.     *     * @param file the "reference" file for relative paths. This     * instance must be an absolute file and must not contain     * &quot;./&quot; or &quot;../&quot; sequences (same for \ instead     * of /).  If it is null, this call is equivalent to     * <code>new java.io.File(filename).getAbsoluteFile()</code>.     *     * @param filename a file name.     *     * @return an absolute file.     * @throws java.lang.NullPointerException if filename is null.     */    public File resolveFile(File file, String filename) {        if (!isAbsolutePath(filename)) {            char sep = File.separatorChar;            filename = filename.replace('/', sep).replace('\\', sep);            if (isContextRelativePath(filename)) {                file = null;                // on cygwin, our current directory can be a UNC;                // assume user.dir is absolute or all hell breaks loose...                String udir = System.getProperty("user.dir");                if (filename.charAt(0) == sep && udir.charAt(0) == sep) {                    filename = dissect(udir)[0] + filename.substring(1);                }            }            filename = new File(file, filename).getAbsolutePath();        }        return normalize(filename);    }    /**     * On DOS and NetWare, the evaluation of certain file     * specifications is context-dependent.  These are filenames     * beginning with a single separator (relative to current root directory)     * and filenames with a drive specification and no intervening separator     * (relative to current directory of the specified root).     * @param filename the filename to evaluate.     * @return true if the filename is relative to system context.     * @throws java.lang.NullPointerException if filename is null.     * @since Ant 1.7     */    public static boolean isContextRelativePath(String filename) {        if (!(ON_DOS || ON_NETWARE) || filename.length() == 0) {            return false;        }        char sep = File.separatorChar;        filename = filename.replace('/', sep).replace('\\', sep);        char c = filename.charAt(0);        int len = filename.length();        return (c == sep && (len == 1 || filename.charAt(1) != sep))                || (Character.isLetter(c) && len > 1                && filename.indexOf(':') == 1                && (len == 2 || filename.charAt(2) != sep));    }    /**     * Verifies that the specified filename represents an absolute path.     * Differs from new java.io.File("filename").isAbsolute() in that a path     * beginning with a double file separator--signifying a Windows UNC--must     * at minimum match "\\a\b" to be considered an absolute path.     * @param filename the filename to be checked.     * @return true if the filename represents an absolute path.     * @throws java.lang.NullPointerException if filename is null.     * @since Ant 1.6.3     */    public static boolean isAbsolutePath(String filename) {        int len = filename.length();        if (len == 0) {            return false;        }        char sep = File.separatorChar;        filename = filename.replace('/', sep).replace('\\', sep);        char c = filename.charAt(0);        if (!(ON_DOS || ON_NETWARE)) {            return (c == sep);        }        if (c == sep) {            // CheckStyle:MagicNumber OFF            if (!(ON_DOS && len > 4 && filename.charAt(1) == sep)) {                return false;            }            // CheckStyle:MagicNumber ON            int nextsep = filename.indexOf(sep, 2);            return nextsep > 2 && nextsep + 1 < len;        }        int colon = filename.indexOf(':');        return (Character.isLetter(c) && colon == 1                && filename.length() > 2 && filename.charAt(2) == sep)                || (ON_NETWARE && colon > 0);    }    /**     * Translate a path into its native (platform specific) format.     * <p>     * This method uses PathTokenizer to separate the input path     * into its components. This handles DOS style paths in a relatively     * sensible way. The file separators are then converted to their platform     * specific versions.     *     * @param toProcess The path to be translated.     *                  May be <code>null</code>.     *     * @return the native version of the specified path or     *         an empty string if the path is <code>null</code> or empty.     *     * @since ant 1.7     * @see PathTokenizer     */    public static String translatePath(String toProcess) {        if (toProcess == null || toProcess.length() == 0) {            return "";        }        StringBuffer path = new StringBuffer(toProcess.length() + EXPAND_SPACE);        PathTokenizer tokenizer = new PathTokenizer(toProcess);        while (tokenizer.hasMoreTokens()) {            String pathComponent = tokenizer.nextToken();            pathComponent = pathComponent.replace('/', File.separatorChar);            pathComponent = pathComponent.replace('\\', File.separatorChar);            if (path.length() != 0) {                path.append(File.pathSeparatorChar);            }            path.append(pathComponent);        }        return path.toString();    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -