栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

真正在Java中强制文件同步/刷新

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

真正在Java中强制文件同步/刷新

您需要向我们详细介绍硬件和操作系统,以及特定的Java版本。您如何测量此吞吐量?

您是正确的,强制/同步应将数据强制输出到物理介质。


这是副本的原始版本。在Intel Mac上与gcc 4.0一起编译,应该干净。

#include <fcntl.h>#include <sys/types.h>#include <sys/uio.h>#include <stdlib.h>#include <unistd.h>#if defined(DIRTY)#   if defined(BUFSIZ)#       error "Don't define your own BUFSIZ when DIRTY"#   endif#   include <stdio.h>#   define PERROR perror(argv[0])#else#   define CLEAN#   define PERROR#   if ! defined(BUFSIZ)#       error "You must define your own BUFSIZ with -DBUFSIZ=<number>"#   endif#endifchar * buffer[BUFSIZ];          extern int errno ;   int main(int argc, char * argv[]) {    int fdi, fdo ;       ssize_t len ;        if(argc != 3){        PERROR;        exit(errno);    }        if((fdi = open(argv[1],O_RDONLY)) == -1){        PERROR;        exit(errno);    }    if((fdo = open(argv[2], O_WRonLY|O_CREAT)) == -1){        PERROR;        exit(errno);    }        while((len = read(fdi, (void *) buffer, BUFSIZ)) > -1){        if(len == -1){ PERROR; exit(errno);        }        if(write(fdo, (void*)buffer, len) == -1){ PERROR; exit(errno);        }    }        if(fsync(fdo) ==-1){        PERROR;        exit(errno);    }    if(close(fdo) == -1){        PERROR;        exit(errno);    }    if(close(fdi) == -1){        PERROR;        exit(errno);    }        exit(0);}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/495776.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号