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实例化操作之前就可以删除了。
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实例化操作之前就可以删除了。











