字符流:FileReader/FileWriter

String instr = "E:\\text.txt";
String oustr = "E:\\b .txt";
FileReader reader = null;
FileWriter writer = null;
char[] b = new char[8];
int readData = 0;
long t1 = System.currentTimeMillis();
try {
reader = new FileReader(instr);
writer = new FileWriter(oustr);
while ((readData = reader.read(b)) != -1) {
writer.write(b, 0, b.length);
}
long t2 = System.currentTimeMillis();
System.out.println("花费时间:" + (t2 - t1));

} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (reader != null) {
reader.close();
}
} catch (IOException e) {
e.printStackTrace();
}

try {
if (writer != null) {
writer.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
posted @ 2022-06-11 13:49  在路上的Spike007  阅读(11)  评论(0)    收藏  举报