博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Java FileDescriptor sync()方法与示例
阅读量:2533 次
发布时间:2019-05-11

本文共 1945 字,大约阅读时间需要 6 分钟。

FileDescriptor类sync()方法 (FileDescriptor Class sync() method)

  • sync() method is available in java.io package.

    sync()方法在java.io包中可用。

  • sync() method is used to synchronize all the system buffer with the underlying device.

    sync()方法用于将所有系统缓冲区与基础设备同步。

  • sync() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.

    sync()方法是一种非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。

  • sync() method may throw an exception at the time of synchronizing.

    sync()方法在同步时可能会引发异常。

    SyncFailedException: This exception may throw when the buffer cannot be flushed or the system cannot be sure synchronization of all the buffers with the underlying device.

    SyncFailedException :当无法刷新缓冲区或系统无法确保所有缓冲区与基础设备同步时,可能引发此异常。

Syntax:

句法:

public void sync();

Parameter(s):

参数:

  • It does not accept any parameter.

    它不接受任何参数。

Return value:

返回值:

The return type of the method is void, it returns nothing.

该方法的返回类型为void ,不返回任何内容。

Example:

例:

// Java program to demonstrate the example // of void sync() method of FileDescriptorimport java.io.*;public class SyncOfFD {
public static void main(String[] args) throws Exception {
FileOutputStream os_stm = null; try {
// Instantiates FileOutputStream os_stm = new FileOutputStream("D:\\includehelp.txt"); // By using getFD() method is to get // the file descriptor FileDescriptor file_des = os_stm.getFD(); // By using write() method is to // write corresponding char 'A' to // the output stream os_stm os_stm.write(65); // By using sync() method is to // sync the data to the file file_des.sync(); System.out.println("Sync() executed "); } catch (Exception ex) {
System.out.println(ex.toString()); } finally {
// with the help of this block is to // free all necessary resources linked // with the stream if (os_stm != null) {
os_stm.close(); } } }}

Output

输出量

Sync() executed

翻译自:

转载地址:http://unxzd.baihongyu.com/

你可能感兴趣的文章
小D课堂 - 零基础入门SpringBoot2.X到实战_第2节 SpringBoot接口Http协议开发实战_12、SpringBoot2.x文件上传实战...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第4节 Springboot2.0单元测试进阶实战和自定义异常处理_19、SpringBoot个性化启动banner设置debug日志...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第4节 Springboot2.0单元测试进阶实战和自定义异常处理_20、SpringBoot2.x配置全局异常实战...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第5节 SpringBoot部署war项目到tomcat9和启动原理讲解_23、SpringBoot2.x启动原理概述...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第4节 Springboot2.0单元测试进阶实战和自定义异常处理_21、SpringBoot2.x配置全局异常返回自定义页面...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第8节 数据库操作之整合Mybaties和事务讲解_32..SpringBoot2.x持久化数据方式介绍...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第8节 数据库操作之整合Mybaties和事务讲解_34、SpringBoot整合Mybatis实操和打印SQL语句...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第8节 数据库操作之整合Mybaties和事务讲解_35、事务介绍和常见的隔离级别,传播行为...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第9节 SpringBoot2.x整合Redis实战_40、Redis工具类封装讲解和实战...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第9节 SpringBoot2.x整合Redis实战_37、分布式缓存Redis介绍...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第10节 SpringBoot整合定时任务和异步任务处理_42、SpringBoot常用定时任务配置实战...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第9节 SpringBoot2.x整合Redis实战_39、SpringBoot2.x整合redis实战讲解...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第14节 高级篇幅之SpringBoot多环境配置_59、SpringBoot多环境配置介绍和项目实战...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第10节 SpringBoot整合定时任务和异步任务处理_41、SpringBoot定时任务schedule讲解...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第10节 SpringBoot整合定时任务和异步任务处理_43、SpringBoot2.x异步任务实战(核心知识)...
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_1_01课程简介
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第11节 Logback日志框架介绍和SpringBoot整合实战_45、SpringBoot2.x日志讲解和Logback配置实战...
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_1_02技术选型
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_汇总
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_2_01传统架构演进到分布式架构
查看>>