标签:reader stack ext exception 创建 ring try 转化 exce
public class Index {
public static void main(String[] args) {
// 创建文件对象
File f1 = new File("src/字节流_转化成_字符流/text.txt");
File f2 = new File("src/字节流_转化成_字符流/textCopy.txt");
try (
// 创建输入输出流(java1.7开始在这里面的代码会自动关闭)
Reader inputStream = new InputStreamReader(new FileInputStream(f1), "GBK");
Writer outputStream = new OutputStreamWriter(new FileOutputStream(f2, true), "GBK");
){
// 声明缓冲数组
char[] b = new char[1024];
// 声明获取字节变量的个数
int len = -1;
while ((len = inputStream.read(b)) != -1) {
// 将读取到的字节数组写入目标文件
outputStream.write(b, 0, len);
}
} catch (Exception e) {
// 输出异常信息
e.printStackTrace();
}
}
}
标签:reader stack ext exception 创建 ring try 转化 exce
原文地址:http://www.cnblogs.com/lovling/p/6308680.html