首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

乞援:读完文件想删除`但失败`

2011-11-28 
求助::读完文件想删除``但失败```FileInputStreamfisnewFileInputStream( test.htm )FileChannelfcfi

求助::读完文件想删除``但失败```
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();
然后再删

热点排行