What kind of FileChannel object does the FileChannel.open(path) method return?

Is it still random access allowed as if it was as following?

RandomAccessFile ra = new RandomAccessFile("RandomIndeed","rw");
FileChannel fc1 = ra.getChannel();

  

What's the difference between fc1 and the following instance fc:

FileChannel fc = FileChannel.open(path);

  

Basically I would like to know what will be the differences between the 2 objects above-created, hence fc1 and fc

Thanks in advance.

 

The FileChannel instance got from RandomAccessFile instance carries the random access behaviour of the object it's been created, in this case fc1 is synced with ra object. You can see it's described in javadoc

Changing the channel's position, whether explicitly or by reading or writing bytes, will change the file position of the originating object, and vice versa. Changing the file's length via the file channel will change the length seen via the originating object, and vice versa. Changing the file's content by writing bytes will change the content seen by the originating object, and vice versa.

However the FileChannel instance which is created using FileChannel.open() which is fc doesn't have this behaviour. This is true for the FileChannel instances you got from Streams. It only guarantees that the view of the file is consistent among the objects created by the same program. Hope this might help you.

RandomAccessFile vs FileChannel.open(path);的更多相关文章

  1. RandomAccessFile、FileChannel、MappedByteBuffer读写文件

    s package com.nio; import java.io.Closeable; import java.io.FileNotFoundException; import java.io.IO ...

  2. FileChannel详解

    经过前两篇文章的学习,相信对Channel有了一定的整体性认识.接下来通过学习本篇文章,更进一步认识Channel,学习FileChannel的细节 用途 特点 api 原理 一.用途 传统IO中的F ...

  3. Java NIO 文件通道 FileChannel 用法

    FileChannel 提供了一种通过通道来访问文件的方式,它可以通过带参数 position(int) 方法定位到文件的任意位置开始进行操作,还能够将文件映射到直接内存,提高大文件的访问效率.本文将 ...

  4. java的nio之:java的nio系列教程之FileChannel

    一:Java NIO的FileChannel===>Java NIO中的FileChannel是一个连接到文件的通道.可以通过文件通道读写文件. ===>FileChannel无法设置为非 ...

  5. Java基础知识强化之IO流笔记78:NIO之 FileChannel

    Java NIO中的FileChannel是一个连接到文件的通道.可以通过文件通道读写文件. FileChannel无法设置为非阻塞模式,它总是运行在阻塞模式下. 1. 打开FileChannel 在 ...

  6. 【原创】java NIO FileChannel 学习笔记 新建一个FileChannel

    首先使用FileChannel 的open方法获取一个FileChannel对象.下面这段代码是FileChannel中open方法的代码. public static FileChannel ope ...

  7. Java NIO系列教程(二) Channel通道介绍及FileChannel详解

    目录: <Java NIO系列教程(二) Channel> <Java NIO系列教程(三) Channel之Socket通道> Channel是一个通道,可以通过它读取和写入 ...

  8. Java NIO系列教程(七) FileChannel

    Java NIO中的FileChannel是一个连接到文件的通道.可以通过文件通道读写文件. FileChannel无法设置为非阻塞模式,它总是运行在阻塞模式下. 打开FileChannel 在使用F ...

  9. FileChannel指南

    推荐关注公众号:锅外的大佬 每日推送国外技术好文,帮助每位开发者更优秀地成长 原文链接:https://www.baeldung.com/java-filechannel 作者:baeldung 译者 ...

随机推荐

  1. OC-bug: Undefined symbols for architecture i386: "_OBJC_CLASS_$_JPUSHRegisterEntity", referenced from:

    bug的提示: Undefined symbols for architecture i386: "_OBJC_CLASS_$_JPUSHRegisterEntity", refe ...

  2. 数据库MySQL学习笔记高级篇

    数据库MySQL学习笔记高级篇 写在前面 学习链接:数据库 MySQL 视频教程全集 1. mysql的架构介绍 mysql简介 概述 高级Mysql 完整的mysql优化需要很深的功底,大公司甚至有 ...

  3. (八)OpenStack---M版---双节点搭建---Cinder安装和配置

    ↓↓↓↓↓↓↓↓视频已上线B站↓↓↓↓↓↓↓↓ >>>>>>传送门 1.创建数据库并授权 2.获得admin凭证执行管理员命令并创建服务证书 3.创建块存储设备AP ...

  4. Rust中的Cargo工作空间实践

    这是为了开发大型程序,分治crate用的. 目录结构如下: 一,根cargo.toml内容 [workspace] members = [ "adder", "add-o ...

  5. APPIUM 常用API介绍(3)

    1.send_keys send_keys(self, *value): Simulates typing into the element[在元素中模拟输入(开启appium自带的输入法并配置了ap ...

  6. 201871010114-李岩松《面向对象程序设计(java)》第十七周学习总结

    项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在哪里 https://www.cnblogs.com/nwnu-daizh/p ...

  7. Nginx ServerName 配置说明

    Nginx强大的正则表达式支持,可以使server_name的配置变得很灵活,如果你要做多用户博客,那么每个用户拥有自己的二级域名也就很容易实现了.下面我就来说说server_name的使用吧:ser ...

  8. windows下载的java项目部署到linux的各种解决方案

    1.Java是跨平台的,在linux下有问题,主要一是文件读取权限:二检查下系统环境变量设置可正确!.profile JavaWeb_将Windows平台上开发的JavaWeb项目部署到Linux平台 ...

  9. pikachu的xss及csrf

    一.XSS 可解析的js 未经过滤 XSS见框就插     script 大小写  中间插入 <img src="" onerror="alert(11111)&q ...

  10. 10-numpy笔记-np.random.randint

    b_idx = np.random.randint(0, 9, 90) >>> b_idx array([0, 1, 5, 4, 7, 2, 7, 0, 0, 4, 2, 2, 3, ...