/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.io;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.Reader;
import java.math.BigInteger;
import java.net.URL;
import java.net.URLConnection;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.zip.CRC32;
import java.util.zip.CheckedInputStream;
import java.util.zip.Checksum;
import org.apache.commons.io.filefilter.DirectoryFileFilter;
import org.apache.commons.io.filefilter.FalseFileFilter;
import org.apache.commons.io.filefilter.FileFilterUtils;
import org.apache.commons.io.filefilter.IOFileFilter;
import org.apache.commons.io.filefilter.SuffixFileFilter;
import org.apache.commons.io.filefilter.TrueFileFilter;
import org.apache.commons.io.output.NullOutputStream;
/**
* General file manipulation utilities.
* <p>
* Facilities are provided in the following areas:
* <ul>
* <li>writing to a file
* <li>reading from a file
* <li>make a directory including parent directories
* <li>copying files and directories
* <li>deleting files and directories
* <li>converting to and from a URL
* <li>listing files and directories by filter and extension
* <li>comparing file content
* <li>file last changed date
* <li>calculating a checksum
* </ul>
* <p>
* Note that a specific charset should be specified whenever possible.
* Relying on the platform default means that the code is Locale-dependent.
* Only use the default if the files are known to always use the platform default.
* <p>
* Origin of code: Excalibur, Alexandria, Commons-Utils
*
*/
public class FileUtils {
/**
* Instances should NOT be constructed in standard programming.
*/
public FileUtils() {
super();
}
/**
* The number of bytes in a kilobyte.
*/
public static final long ONE_KB = 1024;
/**
* The number of bytes in a kilobyte.
*
* @since 2.4
*/
public static final BigInteger ONE_KB_BI = BigInteger.valueOf(ONE_KB);
/**
* The number of bytes in a megabyte.
*/
public static final long ONE_MB = ONE_KB * ONE_KB;
/**
* The number of bytes in a megabyte.
*
* @since 2.4
*/
public static final BigInteger ONE_MB_BI = ONE_KB_BI.multiply(ONE_KB_BI);
/**
* The file copy buffer size (30 MB)
*/
private static final long FILE_COPY_BUFFER_SIZE = ONE_MB * 30;
/**
* The number of bytes in a gigabyte.
*/
public static final long ONE_GB = ONE_KB * ONE_MB;
/**
* The number of bytes in a gigabyte.
*
* @since 2.4
*/
public static final BigInteger ONE_GB_BI = ONE_KB_BI.multiply(ONE_MB_BI);
/**
* The number of bytes in a terabyte.
*/
public static final long ONE_TB = ONE_KB * ONE_GB;
/**
* The number of bytes in a terabyte.
*
* @since 2.4
*/
public static final BigInteger ONE_TB_BI = ONE_KB_BI.multiply(ONE_GB_BI);
/**
* The number of bytes in a petabyte.
*/
public static final long ONE_PB = ONE_KB * ONE_TB;
/**
* The number of bytes in a petabyte.
*
* @since 2.4
*/
public static final BigInteger ONE_PB_BI = ONE_KB_BI.multiply(ONE_TB_BI);
/**
* The number of bytes in an exabyte.
*/
public static final long ONE_EB = ONE_KB * ONE_PB;
/**
* The number of bytes in an exabyte.
*
* @since 2.4
*/
public static final BigInteger ONE_EB_BI = ONE_KB_BI.multiply(ONE_PB_BI);
/**
* The number of bytes in a zettabyte.
*/
public static final BigInteger ONE_ZB = BigInteger.valueOf(ONE_KB).multiply(BigInteger.valueOf(ONE_EB));
/**
* The number of bytes in a yottabyte.
*/
public static final BigInteger ONE_YB = ONE_KB_BI.multiply(ONE_ZB);
/**
* An empty array of type <code>File</code>.
*/
public static final File[] EMPTY_FILE_ARRAY = new File[0];
//-----------------------------------------------------------------------
/**
* Construct a file from the set of name elements.
*
* @param directory the parent directory
* @param names the name elements
* @return the file
* @since 2.1
*/
public static File getFile(final File directory, final String... names) {
if (directory == null) {
throw new NullPointerException("directory must not be null");
}
if (names == null) {
throw new NullPointerException("names must not be null");
}
File file = directory;
for (final String name : names) {
file = new File(file, name);
}
return file;
}
/**
* Construct a file from the set of name elements.
*
* @param names the name elements
* @return the file
* @since 2.1
*/
public static File getFile(final String... names) {
if (names == null) {
throw new NullPointerException("names must not be null");
}
File file = null;
for (final String name : names) {
if (file == null) {
file = new File(name);
} else {
file = new File(file, name);
}
}
return file;
}
/**
* Returns the path to the system temporary directory.
*
* @return the path to the system temporary directory.
*
* @since 2.0
*/
public static String getTempDirectoryPath() {
return System.getProperty("java.io.tmpdir");
}
/**
* Returns a {@link File} representing the system temporary directory.
*
* @return the system temporary directory.
*
* @since 2.0
*/
public static File getTempDirectory() {
return new File(getTempDirectoryPath());
}
/**
* Returns the path to the user's home directory.
*
* @return the path to the user's home directory.
*
* @since 2.0
*/
public static String getUserDirectoryPath() {
return System.getProperty("user.home");
}
/**
* Returns a {@link File} representing the user's home directory.
*
* @return the user's home directory.
*
* @since 2.0
*/
public static File getUserDirectory() {
return new File(getUserDirectoryPath());
}
//-----------------------------------------------------------------------
/**
* Opens a {@link FileInputStream} for the specified file, providing better
* error messages than simply calling <code>new FileInputStream(file)</code>.
* <p>
* At the end of the method either the stream will be successfully opened,
* or an exception will have been thrown.
* <p>
* An exception is thrown
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Java文件管理器项目 (131个子文件)
package.html 9KB
package.html 5KB
package.html 2KB
overview.html 1KB
package.html 991B
package.html 984B
package.html 982B
package.html 950B
FileUtils.java 130KB
IOUtils.java 128KB
FilenameUtils.java 56KB
XmlStreamReader.java 32KB
FileFilterUtils.java 28KB
DirectoryWalker.java 25KB
FileSystemUtils.java 23KB
Tailer.java 21KB
EndianUtils.java 17KB
FileAlterationObserver.java 16KB
CopyUtils.java 16KB
ByteArrayOutputStream.java 14KB
WriterOutputStream.java 14KB
ReversedLinesFileReader.java 14KB
toolBarMenu.java 14KB
BOMInputStream.java 13KB
LockableFileWriter.java 13KB
FileWriterWithEncoding.java 12KB
ReaderInputStream.java 11KB
DeferredFileOutputStream.java 11KB
FileCleaningTracker.java 11KB
NullInputStream.java 11KB
NullReader.java 10KB
CharSequenceInputStream.java 10KB
MagicNumberFileFilter.java 9KB
ObservableInputStream.java 9KB
IOCase.java 9KB
ProxyWriter.java 8KB
ProxyReader.java 8KB
SwappedDataInputStream.java 8KB
Charsets.java 8KB
ProxyInputStream.java 8KB
FileEntry.java 7KB
ThresholdingOutputStream.java 7KB
XmlStreamWriter.java 7KB
WildcardFileFilter.java 7KB
BoundedInputStream.java 7KB
ValidatingObjectInputStream.java 7KB
FileCleaner.java 7KB
SuffixFileFilter.java 7KB
PrefixFileFilter.java 7KB
NameFileFilter.java 6KB
LineIterator.java 6KB
HexDump.java 6KB
ByteOrderMark.java 6KB
FileAlterationMonitor.java 6KB
FileDeleteStrategy.java 6KB
AgeFileFilter.java 5KB
ProxyOutputStream.java 5KB
TeeInputStream.java 5KB
SizeFileComparator.java 5KB
ExtensionFileComparator.java 5KB
AndFileFilter.java 5KB
WildcardFilter.java 5KB
OrFileFilter.java 5KB
BoundedReader.java 5KB
CharSequenceReader.java 5KB
CountingInputStream.java 5KB
PathFileComparator.java 5KB
StringBuilderWriter.java 5KB
NameFileComparator.java 5KB
TaggedIOException.java 4KB
XmlStreamReaderException.java 4KB
CompositeFileComparator.java 4KB
ThreadMonitor.java 4KB
MessageDigestCalculatingInputStream.java 4KB
CountingOutputStream.java 4KB
RegexFileFilter.java 4KB
TaggedOutputStream.java 4KB
TaggedInputStream.java 4KB
FileListPane.java 4KB
WindowsLineEndingInputStream.java 4KB
ClassLoaderObjectInputStream.java 4KB
UnixLineEndingInputStream.java 4KB
NullWriter.java 4KB
SizeFileFilter.java 4KB
DelegateFileFilter.java 3KB
toolBar.java 3KB
AutoCloseInputStream.java 3KB
TeeOutputStream.java 3KB
LastModifiedFileComparator.java 3KB
CanReadFileFilter.java 3KB
BrokenInputStream.java 3KB
DirectoryFileComparator.java 3KB
ChunkedOutputStream.java 3KB
ChunkedWriter.java 3KB
DemuxOutputStream.java 3KB
EmptyFileFilter.java 3KB
FileAlterationListenerAdaptor.java 3KB
NotFileFilter.java 3KB
CanWriteFileFilter.java 2KB
DefaultFileComparator.java 2KB
共 131 条
- 1
- 2
资源评论
- MasterChlorine2023-03-14发现一个宝藏资源,资源有很高的参考价值,赶紧学起来~
- m0_682507822024-04-22资源值得借鉴的内容很多,那就浅学一下吧,值得下载!
- jaychenjp2023-07-10资源内容总结的很到位,内容详实,很受用,学到了~
hexiang@
- 粉丝: 3w+
- 资源: 51
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 【学生课程实验】基于Vue + Node的外卖系统设计与实现【源码+lw+部署文档+讲解】
- 大学生数学建模竞赛论文(长江水质的评价和趋势分析模型)II.zip
- WIN10安装S7-200 SP9不能通讯解决方案
- FreePic2Pdf-v5.01 图片批量转换pdf/双层pdf 书签提取/导入
- 基于区块链的信息追溯系统的设计与实现+详细文档+全部资料(高分毕业设计).zip
- IMG_0796.PNG
- Hyper+Lightning5+SDXL大模型比较推荐
- 基于matlab 模糊神经网络的预测算法-嘉陵江水质评价源代码+详细教程
- PHP8 PDO MYSQL示例
- 毕业设计 基于区块链以及人脸识别的NFT交易系统源码+详细文档+全部资料(高分项目).zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功