zhyiwww
用平实的笔,记录编程路上的点点滴滴………
posts - 536,comments - 394,trackbacks - 0

In some applications, such as transaction processing, it is necessary to ensure that an update has been made to the disk. FileDescriptor.sync() blocks until all changes to a file are written to disk.

				
						    try {
        // Open or create the output file
        FileOutputStream os = new FileOutputStream("outfilename");
        FileDescriptor fd = os.getFD();
    
        // Write some data to the stream
        byte[] data = new byte[]{(byte)0xCA, (byte)0xFE, (byte)0xBA, (byte)0xBE};
        os.write(data);
    
        // Flush the data from the streams and writers into system buffers.
        // The data may or may not be written to disk.
        os.flush();
    
        // Block until the system buffers have been written to disk.
        // After this method returns, the data is guaranteed to have
        // been written to disk.
        fd.sync();
    } catch (IOException e) {
    }
				
		


|----------------------------------------------------------------------------------------|
                           版权声明  版权所有 @zhyiwww
            引用请注明来源 http://www.blogjava.net/zhyiwww   
|----------------------------------------------------------------------------------------|
posted on 2006-06-13 12:01 zhyiwww 阅读(245) 评论(0)  编辑  收藏 所属分类: code demo -java

只有注册用户登录后才能发表评论。


网站导航: