当前位置: 首页 > news >正文

网帆网站建设开发公司移交物业协议书

网帆网站建设,开发公司移交物业协议书,哪些人是建网站的,wordpress 用户点赞插件1、FileChanel介绍 Java NIO FileChannel是连接文件的通道#xff0c;从文件中读取数据和将数据写入文件。Java NIO FileChannel类是NIO用于替代使用标准Java IO API读取文件的方法。 FileInputStream的getChannel方法获取的文件通道是只读的#xff0c;当然通过FileOutput…1、FileChanel介绍 Java NIO FileChannel是连接文件的通道从文件中读取数据和将数据写入文件。Java NIO FileChannel类是NIO用于替代使用标准Java IO API读取文件的方法。 FileInputStream的getChannel方法获取的文件通道是只读的当然通过FileOutputStream的getChannel的方法获取的文件通道是可写的 部分API 1、truncate截断文件功能 /*** Truncates the file underlying this channel to a given size. Any bytes* beyond the given size are removed from the file. If there are no bytes* beyond the given size then the file contents are unmodified.* p* If the file position is currently greater than the given size, then it is* set to the new size.** param size* the maximum size of the underlying file.* throws IllegalArgumentException* if the requested size is negative.* throws ClosedChannelException* if this channel is closed.* throws NonWritableChannelException* if the channel cannot be written to.* throws IOException* if another I/O error occurs.* return this channel.*/public abstract FileChannel truncate(long size) throws IOException; 2、force()强制在内存中的数据刷新到硬盘中去 /*** Requests that all updates to this channel are committed to the storage* device.* p* When this method returns, all modifications made to the platform file* underlying this channel have been committed if the file resides on a* local storage device. If the file is not hosted locally, for example on a* networked file system, then applications cannot be certain that the* modifications have been committed.* p* There are no assurances given that changes made to the file using methods* defined elsewhere will be committed. For example, changes made via a* mapped byte buffer may not be committed.* p* The codemetadata/code parameter indicates whether the update should* include the files metadata such as last modification time, last access* time, etc. Note that passing codetrue/code may invoke an underlying* write to the operating system (if the platform is maintaining metadata* such as last access time), even if the channel is opened read-only.** param metadata* {code true} if the file metadata should be flushed in* addition to the file content, {code false} otherwise.* throws ClosedChannelException* if this channel is already closed.* throws IOException* if another I/O error occurs.*/public abstract void force(boolean metadata) throws IOException; 3、transferFrom可以看出是拷贝从源的position位置的count 字节大小 /*** Reads up to {code count} bytes from {code src} and stores them in this* channels file starting at {code position}. No bytes are transferred if* {code position} is larger than the size of this channels file. Less* than {code count} bytes are transferred if there are less bytes* remaining in the source channel or if the source channel is non-blocking* and has less than {code count} bytes immediately available in its output* buffer.* p* Note that this channels position is not modified.** param src* the source channel to read bytes from.* param position* the non-negative start position.* param count* the non-negative number of bytes to transfer.* return the number of bytes that are transferred.* throws IllegalArgumentException* if the parameters are invalid.* throws NonReadableChannelException* if the source channel is not readable.* throws NonWritableChannelException* if this channel is not writable.* throws ClosedChannelException* if either channel has already been closed.* throws AsynchronousCloseException* if either channel is closed by other threads during this* operation.* throws ClosedByInterruptException* if the thread is interrupted during this operation.* throws IOException* if any I/O error occurs.*/public abstract long transferFrom(ReadableByteChannel src, long position,long count) throws IOException; 2、复制文件常用方法 1、通过普通输入输出流复制文件 public void copyFile(File srcFile, File dstFile) throws FileNotFoundException {InputStream inputStream null;OutputStream outputStream null;try {inputStream new BufferedInputStream(new FileInputStream(srcFile));outputStream new BufferedOutputStream(new FileOutputStream(dstFile));byte[] bytes new byte[1024];int i;//读取到输入流数据然后写入到输出流中去实现复制while ((i inputStream.read(bytes)) ! -1) {outputStream.write(bytes, 0, i);}} catch (Exception e) {e.printStackTrace();} finally {try {if (inputStream ! null)inputStream.close();if (outputStream ! null)outputStream.close();} catch (IOException e) {e.printStackTrace();}}} 2、通过 FileChannel复制文件 public void copyFile(File srcFile, File dstFile) throws IOException {if (srcFile null || !srcFile.exists()) {return;}if (dstFile null || !dstFile.exists()) {return;}FileInputStream fileIns null;FileOutputStream fileOuts null;FileChannel source null;FileChannel destination null;try {fileIns new FileInputStream(srcFile);fileOuts new FileOutputStream(dstFile);source fileIns.getChannel();destination fileOuts.getChannel();destination.transferFrom(source, 0, source.size());} catch (Exception e) {e.printStackTrace();} finally {if (fileIns ! null)fileIns.close();if (fileOuts ! null)fileOuts.close();if (source ! null)source.close();if (destination ! null)destination.close();}} 3、总结 一般复制使用输入输出流进行操作用源文件创建出一个输入流用目标文件创建出一个输出流把输入流的数据读取写入到输出流用fileChannel直接连接输入输出流的文件通道将数据直接写入到目标文件中效率很高尤其是复制文件比较大的时候我们一般采用fileChannel复制文件。
http://www.hn-smt.com/news/74524/

相关文章:

  • MySQL 存储过程事务和锁
  • 你可能需要一部 Iphone
  • 2025成都隔音窗厂家哪家好?优质隔音窗厂家清单请收好
  • 2025年11月28日
  • 第39天(中等题 数据结构)
  • FOC调试笔记
  • CKA 第2题 ingress参考官网时,要注意
  • -2025/11/28
  • 从零开始的云原生之旅(十一):压测实战:验证弹性伸缩效果 - 实践
  • HarmonyOS 应用开发:深入探索截屏与录屏API的创新实践 - 详解
  • 11.28每日总结
  • 2025年终总结
  • P2709 【模板】莫队 / 小B的询问
  • Convolutional Neutral Network(CNN网络)
  • Product Hunt 每日热榜 | 2025-10-30 - 教程
  • 重练算法(代码随想录版) day24 - 回溯part3
  • 详细介绍:【JUnit实战3_21】第十二章:JUnit 5 与主流 IDE 的集成 + 第十三章:用 JUnit 5 做持续集成(上):在本地安装 Jenkins
  • 10个免费查重降重工具分享,降AIGC率工具
  • Jetlinks 物联网平台 开源版学习源码分析
  • 2025年11月电动叉车销售企业避坑指南:市场主流品牌横向对比
  • 替代模型简化复杂物理仿真任务
  • 【Microsoft Learn】Microsoft Azure 服务 - 教程
  • W55MH32 网络继电器三模自由控制:小程序按键网页随选 - 实践
  • 11月28号
  • 2025全年套管、绝缘套管、热收缩套管、热缩套管、热缩管厂家综合推荐与选购指南
  • Jenkins 已成过去式!新兴替代软件GitHub Actions即将崛起
  • XYD11.25模拟赛
  • P11261
  • P10173
  • 全球首个语音 AI 广告平台问世;Sam Altman 与 Jony Ive:合作新硬件将「如湖畔山间小屋般平静」丨日报