Java中的 FileStore type() 方法及示例
FileStore类的type()方法用于返回此文件存储的类型和返回的字符串的格式,高度特定于实现。
句法:
public abstract String type()
参数:此方法不接受任何内容。
返回值:此方法返回一个表示此文件存储类型的字符串。
下面的程序说明了 type() 方法:
方案一:
Java
// 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();
}
}
}
Java
// 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();
}
}
}
输出:
方案二:
Java
// 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: Java/nio/file/FileStore.html#type()