例子
以下示例显示java.io.DataInputStream.readUTF(DataInput in)方法的用法。
package com.jc2182;
import java.io.FileOutputStream;
import java.io.IOException;
public class FileOutputStreamAvailable extends FileOutputStream {
public FileOutputStreamAvailable() throws Exception {
super("C://test.txt");
}
public static void main(String[] args) throws IOException {
FileOutputStreamAvailable fosa = null;
try {
// create new File input stream
fosa = new FileOutputStreamAvailable();
// read byte from file input stream
fosa.finalize();
// converts int to char
System.out.println("Stream is closed successfully.");
} catch(Exception ex) {
// if any error occurs
ex.printStackTrace();
} finally {
// releases all system resources from the streams
if(fos!=null)
fos.close();
}
}
}
假设我们有一个文本文件c:/test.txt ,其内容如下。该文件将用作示例程序的输入-
让我们编译并运行以上程序,这将产生以下结果-
Stream is closed successfully.