关于文件读写使用RandomAccessFile类的一些简单操作

最近接触到了一些关于文件生成以及文件内容写入的工作任务,关于文件的一些方法常用的是 java.io.File包中的一些方法。这些方法是在java1.0的时候提供的。然后在File类的注释中看到了这个包java.nio.file.Files;随后查看了一下这个包。简单了解了一下

File

/**
 * An abstract representation of file and directory pathnames.
 .......
* <h3>Interoperability with {@code java.nio.file} package</h3>
 *
 * <p> The <a href="../../java/nio/file/package-summary.html">{@code java.nio.file}</a>
 * package defines interfaces and classes for the Java virtual machine to access
 * files, file attributes, and file systems. This API may be used to overcome
 * many of the limitations of the {@code java.io.File} class.
 * The {@link #toPath toPath} method may be used to obtain a {@link
 * Path} that uses the abstract path represented by a {@code File} object to
 * locate a file. The resulting {@code Path} may be used with the {@link
 * java.nio.file.Files} class to provide more efficient and extensive access to
 * additional file operations, file attributes, and I/O exceptions to help
 * diagnose errors when an operation on a file fails.
 *
 * @author  unascribed
 * @since   JDK1.0
 */

public class File
    implements Serializable, Comparable<File>
{
   
	.....
}

从这段注释的说明中可以看出Files类是对原File类的一些操作的扩展。

Files

/**
 * This class consists exclusively of static methods that operate on files,
 * directories, or other types of files.
 *
 * <p> In most cases, the methods defined here will delegate to the associated
 * file system provider to perform the file operations.
 *
 * @since 1.7
 */

public final class Files {
   
    private Files() {
    }
    
....
}

这个包是nio下的关于文件操作的一系列类似于工具包的类。这个类中只包含了对文件,目录和其他类型的文件操作的静态方法。

查了 一下关于这个类的使用是与java.nio.file.Path一起使用的。

关于Path类是可以使用在多线程的情况下。

/**
 * An object that may be used to locate a file in a file system. It will
 * typically represent a system dependent file path.
 .....
  * <h2>Concurrency</h2>
 * <p> Implementations of this interface are immutable and safe for use by
 * multiple concurrent threads.
 *
 * @since 1.7
 * @see Paths
 */
public interface Path
    extends Comparable<Path>, Iterable<Path>, Watchable
{
   
    /**
     * Returns the file system that created this object.
     *
     * @return  the file system that created this ob
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值