/**
* 字符流复制文本
* @author breeziness
*
*/
public class IODemo03 {
public static void main(String[] args) {
// TODO Auto-generated method stub
copy("abc.txt", "abc-copy.txt");
}
public static void copy(String source, String dest) {
Reader reader = null;
Writer writer = null;
char[] buff = new char[1024];
try {
reader = new FileReader(source);
writer = new FileWriter(dest);
while (reader.read(buff) != -1) {
writer.write(buff);
writer.flush();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
if (writer != null) {
writer.close();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
if (reader != null) {
reader.close();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
字符流复制文本
猜你喜欢
转载自blog.csdn.net/qq_40731414/article/details/86531117
今日推荐
周排行