Common method 3 --- File IO class technology stream 2 --- Porter (still Silicon Valley)

  • File class determining function
@Test 
public void Test5 () { 
    File = new new File ( "hello.txt") File; 

    // determines whether the file directory 
    System.out.println (file.isDirectory ()); 
    // determines whether the file 
    System.out .println (file.isFile ()); 
    // determines whether there 
    System.out.println (File.Exists ()); 
    // determines whether readable 
    System.out.println (file.canRead ()); 
    // Analyzing is writable 
    System.out.println (file.canWrite ()); 
    // determines whether hidden 
    System.out.println (file.isHidden ()); 
}
  • File class to create and delete
@Test 
public void Test5 () { 
    File = new new File ( "hello.txt") File; 

    // determines whether the file directory 
    System.out.println (file.isDirectory ()); 
    // determines whether the file 
    System.out .println (file.isFile ()); 
    // determines whether there 
    System.out.println (File.Exists ()); 
    // determines whether readable 
    System.out.println (file.canRead ()); 
    // Analyzing can write 
    System.out.println (file.canWrite ()); 
    // determine whether to hide 
    System.out.println (file.isHidden ()); 
} 

create and delete file class 
// create a file 
@Test 
public void test6 () throws IOException { 
    File = new new File ( "hi.txt") File; 
    IF (File.Exists ()!) { 
        file.createNewFile (); 
        System.out.println ( "successfully created");
    the else {} 
        File.delete (); 
        System.out.println ( "deleted successfully"); 
    } 
} 

// Create a file directory 
@Test 
public void TEST7 () { 
    // Create a file directory. If the file directory exists, not created. If the parent directory file directory does not exist, nor created. 
    File file1 = new File ( "C : \\ Users \\ Mi \\ Documents \\ io \\ absence IO1 folder \\"); 
    Boolean mkdir1 file1.mkdir = (); 
    IF (mkdir1) { 
        the System. out.println ( "Creating success 1"); 
    } 

    // create a file directory. If the upper layer file directory does not exist, create together 
    File file2 = new File ( "C : \\ Users \\ Mi \\ Documents \\ io \\ does not exist io2 folder \\"); 
    boolean mkdir2 = file2.mkdirs (); 
    IF (mkdir2) { 
        System.out.println ( "successfully created 2"); 
    } 
}

  

 

Guess you like

Origin www.cnblogs.com/noyouth/p/11699192.html