public FileReader(String fileName)
throws FileNotFoundException
public FileReader(File file)
throws FileNotFoundException
public int read()
throws IOException
package java19;
import java.io.FileReader;
import java.io.IOException;
/**
* 2017/10/12
* 说明:
*/
public class FileReaderDemo {
public static void main(String[] args) {
FileReader fr = null;
try {
fr = new FileReader("demo.txt");
int ch = 0;
while((ch = fr.read()) != -1){
System.out.print((char)ch);
}
}catch (IOException e){
e.printStackTrace();
}finally {
if(fr != null){
try {
fr.close();
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("流关闭失败"+e.getMessage());
}
}
}
}
}
public int read(char[] cbuf)
throws IOException
package java19;
import java.io.FileReader;
import java.io.IOException;
/**
* 2017/10/12
* 说明:
*/
public class FileReaderDemo {
public static void main(String[] args) {
FileReader fr = null;
try {
fr = new FileReader("demo.txt");
char[] chs = new char[1024];
int length = 0;
while((length = fr.read(chs)) != -1){
System.out.print(new String(chs,0,length));
}
}catch (IOException e){
e.printStackTrace();
}finally {
if(fr != null){
try {
fr.close();
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("流关闭失败"+e.getMessage());
}
}
}
}
}
package java19;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
/**
* 2017/10/12
* 说明:
*/
public class FileCopy {
public static void main(String[] args) throws IOException {
//创建输入流和输出流
FileReader fr = new FileReader("demo.txt");
FileWriter fw = new FileWriter("test1.txt");
//文件复制
int ch = 0;
while((ch = fr.read()) != -1){
fw.write(ch);
}
//关闭流
fr.close();
fw.close();
}
}
package java19;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
/**
* 2017/10/12
* 说明:
*/
public class FileCopy {
public static void main(String[] args) throws IOException {
//创建输入流和输出流
FileReader fr = new FileReader("demo.txt");
FileWriter fw = new FileWriter("test2.txt");
//文件复制
char[] buffer = new char[1024];
int len = 0 ;
while((len = fr.read(buffer) )!= -1){
fw.write(buffer,0,len);
}
//关闭流
fr.close();
fw.close();
}
}