例子
以下示例显示java.io.FileOutputStream.getFD()方法的用法。
package com.jc2182;
import java.io.FileDescriptor;
import java.io.FileOutputStream;
import java.io.IOException;
public class FileOutputStreamDemo {
public static void main(String[] args) throws IOException {
FileOutputStream fos = null;
FileDescriptor fd = null;
boolean bool = false;
try {
// create new file output stream
fos = new FileOutputStream("C://test.txt");
// get file descriptor instance
fd = fos.getFD();
// test if the file is valid
bool = fd.valid();
// print
System.out.print("Is file valid? "+bool);
} catch(Exception ex) {
// if an error occurs
ex.printStackTrace();
} finally {
if(fos!=null)
fos.close();
}
}
}
让我们编译并运行以上程序,这将产生以下结果-