网站首页 新闻首页 网页设计图形动画软件编程网站开发办公软件操作系统数据库网络技术认证考试范文资料黑客攻防 书籍教程 进入论坛

急!!!JAVA Bug!

http://www.diybl.com/ 2007-12-6  网络 点击:  [ 评论 ]
文章搜索:    【点击打包该文章】

 用到NIO的相关类--MappedByteBuffer时的一个BUG。
例如:

 



public void testMappedByteBufferRead() {
    
int length = 10485760;
    MappedByteBuffer out 
= null;
    RandomAccessFile ranFile 
= null;
    File file 
= null;
    
try {
        file 
= new File("d:/test.txt");
        ranFile 
= new RandomAccessFile(file, "rw");
        out 
= ranFile.getChannel().map(
        FileChannel.MapMode.READ_WRITE, 
0, length);
        
for (int i = 0; i < length; i++)
            out.put((
byte''x'');
        System.out.println(
"Finished writing");
    } 
catch (FileNotFoundException e) {
        e.printStackTrace();
    } 
catch (IOException e) {
        e.printStackTrace();
    }
    
try {
        file.delete();
        System.out.println(
"Delete File");
                                Thread.sleep(
100000);
    } 
catch (Exception e) {
        e.printStackTrace();
    }
}

上面的操作都会正常的完成,除了最后一步:文件无法删除!即使你通过资源管理器直接强制删除也不行,说"文件正在使用",也就是说out无法关闭!

在网上收集一些资料都说是JAVA的一个BUG,一些网友自己写out的close()函数:


public static void clean(final Object buffer) throws Exception {
       AccessController.doPrivileged(
new PrivilegedAction() {
    
public Object&n
文章整理:DIY部落 http://www.diybl.com (本站)   【点击打包该文章】
[1] [2]
如果图片或页面不能正常显示请点击这里 站内搜索:   
上一篇文章:一些基础的JAVA知识
下一篇文章:Orange开发日志(5)

文章评论

请您留言