示意此笼统路径名的文件是一个文件,该要领返回true,不然该要领返回false。
非常 (引荐进修:java课程)
SecurityException -- 假如平安管理器存在而且其SecurityManager.checkRead(java.lang.String) 要领谢绝对文件的读接见
例子
下面的示例演示java.io.File.isFile()要领的用法。
package com.test; import java.io.File; public class FileDemo { public static void main(String[] args) { File f = null; String path; boolean bool = false; try{ // create new file f = new File("c:"); // true if the file path is a file, else false bool = f.isFile(); // get the path path = f.getPath(); // prints System.out.println(path+" is file? "+ bool); // create new file f = new File("c:/test.txt"); // true if the file path is a file, else false bool = f.isFile(); // get the path path = f.getPath(); // prints System.out.print(path+" is file? "+bool); }catch(Exception e){ // if any error occurs e.printStackTrace(); } } }
让我们编译和运转上面的顺序,这将发生以下效果:
c: is file? false c:est.txt is file? true
以上就是java怎样推断是不是为文件的细致内容,更多请关注ki4网别的相干文章!