文件字符输入流 FileReader类
文件字符输出流 FileWriter类
文件字符输入流的构造方法
用文件名name创建一个文件字符输入流对象
public FileReader(String name)
例如:FileReader in = new FileReader ("a.txt");
用File对象创建一个文件字符输入流对象
public FileReader(File file)
例如:File file=new File("data\\b.txt");
FileReader in = new FileReader(file);
文件字符输入流的读方法
FileReader类的对象调用read()方法顺序地读取文
件,直到文件的末尾或者流被关闭, read()方法
如下所示
?public int read() throws IOException
? public int read(char[ ] cbuf) throws IOException
? public int read(char[ ] cbuf, int off, int len) throwsIOException
读取位置达到文件末尾,则返回-1
—————————————————————————————
文件字符流输出流的构造方法
文件字符输出流FileWriter类按字符将数据写到文件中
用文件名name创建一个文件字符输出流
public FileWriter(String name)
例如:FileWriter out = new FileWriter ("a.txt");
用File对象创建一个文件字符输出流对象
public FileWriter(File file)
例如:File file=new File("data\\b.txt");
FileWriter out= new FileWriter (file);
文件字符流输出流的写方法
FileWriter类的对象调用write()方法顺序地把字符数据写入文件
write()方法如下所示
public void write(int c) throws IOException:
写一个字符
public void write(char[ ] cbuf) throws IOException:
写cbuf.length个字符
public void write(char[ ] cbuf, int off, int len) throws IOException:
写数组片段
public void write(String str) throws IOException:
写全部的字符串
public void write(String str, int off, int len) throws IOException:
写字符串片段
cs