匿名用户
1级
2016-05-25 回答
package com.yiibai;
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:\test.txt");
// true if the file path is absolute, else false
bool = f.isAbsolute();
// get the path
path = f.getPath();
// prints
System.out.println(path+" is absolute? "+ bool);
// create new file
f = new File("test.txt");
// true if the file path is absolute, else false
bool = f.isAbsolute();
// get the path
path = f.getPath();
// prints
System.out.print(path+" is absolute? "+bool);
}catch(Exception e){
// if any error occurs
e.printStackTrace();
}
}
}
让我们编译和运行上面的程序,这将产生以下结果:
C:est.txt is absolute? true
test.txt is absolute? false