public class Test11 {
public static void main(String[] args) {
long start = System.currentTimeMillis();
myCopy();
long end = System.currentTimeMillis();
//运行时间
System.out.println(end-start+"毫秒");
}
public static void myCopy()
{
Reader read =null;
Writer writer = null;
try {
// 生成读写流对象,指定要操作的文件。
read = new FileReader("d:\\1.txt");
writer = new FileWriter("d:\\copy.txt");
char[] chs =new char[100];
int len = 0;
//复制文件
while((len=read.read(chs))!=-1)
{
writer.write(chs,0,len);
writer.flush();
}
} catch ( IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally
{
if(read!=null)
try {
read.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(writer!=null)
try {
writer.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
|
|