- Java.io 包中的类
- Java.io - 首页
- Java.io - BufferedInputStream
- Java.io - BufferedOutputStream
- Java.io - BufferedReader
- Java.io - BufferedWriter
- Java.io - ByteArrayInputStream
- Java.io - ByteArrayOutputStream
- Java.io - CharArrayReader
- Java.io - CharArrayWriter
- Java.io - Console
- Java.io - DataInputStream
- Java.io - DataOutputStream
- Java.io - File
- Java.io - FileDescriptor
- Java.io - FileInputStream
- Java.io - FileOutputStream
- Java.io - FilePermission
- Java.io - FileReader
- Java.io - FileWriter
- Java.io - FilterInputStream
- Java.io - FilterOutputStream
- Java.io - FilterReader
- Java.io - FilterWriter
- Java.io - InputStream
- Java.io - InputStreamReader
- Java.io - LineNumberInputStream
- Java.io - LineNumberReader
- Java.io - ObjectInputStream
- Java.io - ObjectInputStream.GetField
- Java.io - ObjectOutputStream
- Java.io - ObjectOutputStream.PutField
- Java.io - ObjectStreamClass
- Java.io - ObjectStreamField
- Java.io - OutputStream
- Java.io - OutputStreamWriter
- Java.io - PipedInputStream
- Java.io - PipedOutputStream
- Java.io - PipedReader
- Java.io - PipedWriter
- Java.io - PrintStream
- Java.io - PrintWriter
- Java.io - PushbackInputStream
- Java.io - PushbackReader
- Java.io - RandomAccessFile
- Java.io - Reader
- Java.io - SequenceInputStream
- Java.io - SerializablePermission
- Java.io - StreamTokenizer
- Java.io - StringBufferInputStream
- Java.io - StringReader
- Java.io - StringWriter
- Java.io - Writer
- Java.io 包的其他内容
- Java.io - 接口
- Java.io - 异常
- Java.io 包 - 有用资源
- Java.io - 讨论
Java - File getTotalSpace() 方法
描述
Java File getTotalSpace() 方法返回此抽象路径名所命名的分区的大小。
声明
以下是java.io.File.getTotalSpace() 方法的声明:
public long getTotalSpace()
参数
无
返回值
该方法返回分区的字节大小。
异常
SecurityException - 如果已安装安全管理器并且它拒绝 RuntimePermission("getFileSystemAttributes") 或其 SecurityManager.checkRead(String) 方法拒绝对文件的读取访问权限。
示例 1
以下示例演示了 Java File getTotalSpace() 方法的用法。我们创建了一个 File 引用。然后,我们使用提供的 F:/test 目录创建一个 File 对象。现在,使用 getTotalSpace() 方法,我们获取分区中的总空间。
package com.tutorialspoint;
import java.io.File;
public class FileDemo {
public static void main(String[] args) {
File f = null;
long v;
boolean bool = false;
try {
// create new file
f = new File("F:\\test.txt");
// get number of allocated bytes
v = f.getTotalSpace();
// true if the file path exists
bool = f.exists();
// if file exists
if(bool) {
// prints
System.out.print("number of allocated bytes: "+v);
}
} catch(Exception e) {
// if any error occurs
e.printStackTrace();
}
}
}
输出
让我们编译并运行上述程序,这将产生以下结果:
number of allocated bytes: 177142231040
示例 2
以下示例演示了 Java File getTotalSpace() 方法的用法。我们创建了一个 File 引用。然后,我们使用提供的 C:/test 目录创建一个 File 对象。现在,使用 getTotalSpace() 方法,我们获取分区中已分配的字节数。
package com.tutorialspoint;
import java.io.File;
public class FileDemo {
public static void main(String[] args) {
File f = null;
long v;
boolean bool = false;
try {
// create new file
f = new File("C:\\test");
// get number of allocated bytes
v = f.getTotalSpace();
// true if the file path exists
bool = f.exists();
// if file exists
if(bool) {
// prints
System.out.print("number of allocated bytes: "+v);
}
} catch(Exception e) {
// if any error occurs
e.printStackTrace();
}
}
}
输出
让我们编译并运行上述程序,这将产生以下结果:
number of allocated bytes: 62230548480
java_file_class.htm
广告