Java数据流 文件
文件操作
import java.io.File; public class UseFile { public static void main(String args[]){ File f = new File("file1.txt"); System.out.println("the file is exists? "+ f.exists()); System.out.println("the file is write? " + f.canWrite()); System.out.println("the file is read ? "+ f.canRead()); System.out.println("the file is a file " +f.isFile()); System.out.println("the file's path is ? "+ f.getPath()); System.out.println("the file's absolute path is "+ f.getAbsolutePath()); System.out.println("the file's parent path is ?" + f.getParent()); File newfile = new File("newfile.txt"); f.renameTo(newfile); System.out.println(newfile.getName()); System.out.println("if file is exists?" + f.exists()); f.delete(); newfile.delete(); System.out.println("if file is exists?" + f.exists()); } }
这是对文件的一些基本操作