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.
相关文章推荐
- [Java] Constructor 构造方法
- (教学思路 C#之类七)类和构造方法的继承(base关键字、Object类)
- JAVA this关键字用在构造方法中
- Objective-C构造方法
- Java构造和解析Json数据的两种方法详解2
- java--类与对象、构造方法、this、类变量(静态)、类方法、抽象、封装、继承、多态的回顾
- 一个简单方法:构造xml的document,并将其转换为string
- JAVA OOP(二)——方法的重载、构造方法以及this关键字
- Java构造和解析Json数据的两种方法详解2
- JavaSE 学习参考:构造方法
- 域初始化、静态块及构造方法等在创建类实例时的执行顺序
- 静态代码块、普通代码块、构造方法、静态方法以及普通成员方法允许顺序
- java中什么是构造方法及其作用
- java中类,对象,构造方法,封装的概念及描述
- 12.Scala中的继承:超类的构造、重写字段、重写方法代码实战
- 构造方法的运用
- 构造方法与成员方法
- 通过反射获取构造方法,属性,方法信息
- 面向对象基础 之-定义类,声明,属性,成员方法,传值,构造与析构方法
- java 初始化顺序以及由此可能引发的构造方法的潜在问题。