<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