java吧 关注:1,285,690贴子:12,810,433
  • 1回复贴,共1

谁能给我解释一下,这条程序为什么会删除失败。

取消只看楼主收藏回复

public class ScannerDemo02{
public static void main(String args[]) throws IOException{
File f = new File("d:"+File.separator+"text.txt") ;
FileOutputStream w = new FileOutputStream(f,true) ;
w.write("Hello World!!!\n".getBytes()) ;
w.close() ;
Scanner in = new Scanner(f) ;
in.useDelimiter("\t") ;
String s = in.next() ;
System.out.println(s) ;
System.out.println(f.delete());
System.out.println(f.exists());
}
}
f.delete()返回false,为什么?
放到scanner实例化操作之前就可以删除了。


1楼2015-05-08 14:54回复


    2楼2015-05-08 15:06
    回复