日期:2014-05-20  浏览次数:20799 次

求助::读完文件想删除``但失败```
FileInputStream   fis   =   new   FileInputStream( "test.htm ");
FileChannel   fc   =   fis.getChannel();
ByteBuffer   bbuf   =   fc.map(FileChannel.MapMode.READ_ONLY,   0,   (int)   fc.size());
CharBuffer   cbuf   =   Charset.forName( "utf-8 ").newDecoder().decode(bbuf);
String   str   =   new   String(cbuf.array());

//....对str的操作

cbuf.clear();
bbuf.clear();
fc.close();
fis.close();

File   f   =   new   File( "test.htm ");
f.delete();     //------这里返回了false,文件删除不了``

听说是什么共享的问题,自己都搞不掂```
请帮忙~~

------解决方案--------------------
MappedByteBuffer的文档说 "映射的字节缓冲区和它所表示的文件映射关系在该缓冲区本身成为垃圾回收缓冲区之前一直保持有效 "试试在
cbuf.clear();
bbuf.clear();
fc.close();
fis.close();
后加fc=null;System.gc();
然后再删