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,文件删除不了``听说是什么共享的问题,自己都搞不掂```
请帮忙~~

解决方案 »

  1.   

    加一个if(file.exists())
    {
      file.delete();
    }
      

  2.   

    AWUSOFT
    加一个if(file.exists())
    {
      file.delete();
    }文件是肯定存在的
      

  3.   

    我想问的是,你确认test.htm没有被别的程序打开着?太奇怪了。
      

  4.   

    不知道是不是FileChannel的问题``
    我的文本文件有3M多``
    读完文件后就要删,
    如果不是FileChannel快些我都不用他``
    现在读完后删不了```郁闷
      

  5.   

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

  6.   

    jefyjiang牛``一言惊醒梦中人```结帖