您的位置:首页 > 编程语言 > PHP开发

FileOutputStream和FileInputStream的构造方法

2011-05-09 19:57 239 查看
package com.dengwen8;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
public class IOTest {
/**
* Which two construct an OutputSream that appends to the file “file.txt”? (Choose Two)
A. OutputStream out=new FileOutputStream(“file.txt”);
B. OutputStream out=new FileOutputStream(“file.txt”, “append”);
C. FileOutputStream out=new FileOutputStream(“file.txt”, true);
D. FileOutputStream out=new FileOutputStream(new file(“file.txt”));
E. OutputStream out=new FileOutputStream(new File(“file.txt”)true);

FileOutputStream类有两个构造函数。
FileOutputStream(String name, boolean append)
FileOutputStream(File file,boolean append)
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
OutputStream ops1=new FileOutputStream("e://lidengwen.txt", true);

OutputStream ops2=new FileOutputStream(new File("e://lidengwen8.txt"), true);
byte[]b=new byte[1024];
String name="lidengwen";
b=name.getBytes();

ops1.write(b);

ops2.write(b);

} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
}


Which two create an InputStream and open file the “file.txt” for reading? (Choose Two)

A. InputStream in=new FileReader(“file.txt”);

B. InputStream in=new FileInputStream(“file.txt”);

C. InputStream in=new InputStreamFileReader (“file.txt”, “read”);

D. FileInputStream in=new FileReader(new File(“file.txt”));

E. FileInputStream in=new FileInputStream(new File(“file.txt”));

Answer: B, E

Which two construct an OutputSream that appends to the file “file.txt”? (Choose Two)

A. OutputStream out=new FileOutputStream(“file.txt”);

B. OutputStream out=new FileOutputStream(“file.txt”, “append”);

C. FileOutputStream out=new FileOutputStream(“file.txt”, true);

D. FileOutputStream out=new FileOutputStream(new file(“file.txt”));

E. OutputStream out=new FileOutputStream(new File(“file.txt”)true);

Answer: C, E

Which constructs a BufferedIputStream?

A. New BufferedInputStream(“in.txt”);

B. New BufferedInputStream(new File(“in.txt”));

C. New BufferedInputStream(new Writer(“in.txt”));

D. New BufferedInputStream(new Writer(“in.txt”));

E. New BufferedInputStream(new InputStream(“in.txt”));

F. New BufferedInputStream(new FileInputStream(“in.txt”));

Answer: F

java.io

Class FileInputStream

Constructor Summary

FileInputStream(File file)

Creates a FileInputStream by opening a connection to an actual file, the file named by the File object file in the file system.

FileInputStream(String name)

Creates a FileInputStream by opening a connection to an actual file, the file named by the path name name in the file system.

java.io

Class FileOutputStream

Constructor Summary

FileOutputStream(File file)

Creates a file output stream to write to the file represented by the specified File object.

FileOutputStream(File file, boolean append)

Creates a file output stream to write to the file represented by the specified File object.

FileOutputStream(String name)

Creates an output file stream to write to the file with the specified name.

FileOutputStream(String name, boolean append)

Creates an output file stream to write to the file with the specified name.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: