<a href="http://www.verejava.com/?id=17160003163645">http://www.verejava.com/?id=17160003163645</a>java
import java.io.File; import java.io.IOException; public class Test { public static void main(String[] args) { // File f=File(String pathname) File f=new File("test.txt"); try { // boolean createNewFile() 若是文件不存在建立一個新的空文件,若是存在不建立 f.createNewFile(); // String getAbsolutePath() //得到文件的絕對路徑 System.out.println(f.getAbsolutePath()); // String getName() //得到文件名稱 System.out.println(f.getName()); // long length() //得到文件裏面內容字節大小 System.out.println(f.length()); // boolean renameTo(File dest) //重命名文件 f.renameTo(new File("rename.txt")); // boolean isFile() //判斷是不是文件 System.out.println(f.isFile()); // boolean exists() //判斷此文件是否存在 System.out.println(f.exists()); // boolean delete() //刪除文件 System.out.println(f.delete()); } catch (IOException ex) { ex.printStackTrace(); } } }
<a href="http://www.verejava.com/?id=17160003163645">http://www.verejava.com/?id=17160003163645</a>code