當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Java FileStore type()用法及代碼示例

FileStore類的type()方法用於返回此文件存儲的類型和高度特定於實現的返回字符串的格式。

用法:

public abstract String type()

參數:此方法不接受任何內容。


返回值:此方法返回一個表示此文件存儲類型的字符串。

以下示例程序旨在說明type()方法:
程序1:

// Java program to demonstrate 
// FileStore.type() method 
  
import java.io.IOException; 
import java.nio.file.FileStore; 
import java.nio.file.Files; 
import java.nio.file.Path; 
import java.nio.file.Paths; 
  
public class GFG { 
  
    public static void main(String[] args) 
    { 
        // create object of Path 
        Path path 
            = Paths.get( 
                "E:\\Tutorials\\file.txt"); 
  
        // get FileStore object 
        try { 
  
            FileStore fs 
                = Files.getFileStore(path); 
  
            // print FileStore name 
            // and Total usable space 
            System.out.println("FileStore Name: "
                               + fs.name()); 
            String type = fs.type(); 
            System.out.println("Type: "
                               + type); 
        } 
        catch (IOException e) { 
  
            // TODO Auto-generated catch block 
            e.printStackTrace(); 
        } 
    } 
}

輸出:

程序2:

// Java program to demonstrate 
// FileStore.type() method 
  
import java.io.IOException; 
import java.nio.file.FileStore; 
import java.nio.file.Files; 
import java.nio.file.Path; 
import java.nio.file.Paths; 
  
public class GFG { 
  
    public static void main(String[] args) 
    { 
        // create object of Path 
        // create object of Path 
        Path path 
            = Paths.get( 
                "C:\\Movies\\document.txt"); 
  
        // get FileStore object 
        try { 
  
            FileStore fs 
                = Files.getFileStore(path); 
  
            // print FileStore name 
            // and Total usable space 
            System.out.println("FileStore Name: "
                               + fs.name()); 
            String type = fs.type(); 
            System.out.println("Type: "
                               + type); 
        } 
        catch (IOException e) { 
  
            // TODO Auto-generated catch block 
            e.printStackTrace(); 
        } 
    } 
}

輸出:

參考:https://docs.oracle.com/javase/10/docs/api/java/nio/file/FileStore.html#type()



相關用法


注:本文由純淨天空篩選整理自AmanSingh2210大神的英文原創作品 FileStore type() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。