@author ixenos
摘要:创建文件、文件过滤、流分类、流结构、常见流、文件流、字节数组流(缓冲区)
如何创建一个文件
#当我们调用File类的构造器时,仅仅是在运行时创建了一个File对象,而不是在文件系统中创建了一个文件。File类可以表示文件系统中存在的目录或文件,也可以表示尚不存在的
#File.separator是一个跨平台的分隔符 (Win用"\",同时"\"又做反义字符,所以"\\"才表示分隔符;UNIX用"/")
1.调用File对象的createNewFile()方法
1 class FileTest1{ 2 public static void main(String[] args){ 3 File testFile = new File("c:\\test"); 4 System.out.println(testFile.getAbsolutePath() + "是否存在" + testFile.exists()); 5 6 try{ 7 testFile.createNewFile(); //创建文件 8 }catch(IOException e){ 9 e.printStackTrace(); 10 } 11 12 System.out.println(testFile.getAbsolutePath() + "是否存在" + testFile.exists()); 13 14 //测试目录创建mkdirs() 15 File testDir = new File("c:\\a\\b\\c"); 16 System.out.println(testFile.getAbsolutePath() + "是否存在" + testFile.exists()); 17 18 testDir.mkdirs(); 19 System.out.println(testFile.getAbsolutePath() + "是否存在" + testFile.exists()); 20 } 21 } 22 23 ------------------------------------- 24 c:\test 是否存在:false 25 26 c:\test 是否存在:true 27 28 c:\a\b\c 是否存在:false 29 30 c:\a\b\c 是否存在:true