通過(guò)輸入輸出流解決此問(wèn)題,具體的可以查看JDK的API,實(shí)在不會(huì)的話(huà),百度一下應(yīng)該都有一堆這方面的代碼。
創(chuàng)新互聯(lián)公司于2013年創(chuàng)立,是專(zhuān)業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項(xiàng)目成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站建設(shè)網(wǎng)站策劃,項(xiàng)目實(shí)施與項(xiàng)目整合能力。我們以讓每一個(gè)夢(mèng)想脫穎而出為使命,1280元沂南做網(wǎng)站,已為上家服務(wù),為沂南各地企業(yè)和個(gè)人服務(wù),聯(lián)系電話(huà):18980820575
package com.teven.comefromnet;
/**
* Name:C.java
* Founction:
* Created:2011-9-15
* @author :teven
*/
public class CloneTest {
static class A implements Cloneable{
int i=1;
@Override
protected A clone() throws CloneNotSupportedException {
return (A)super.clone();
}
}
static class B extends A{
int j=2;
@Override
protected B clone() throws CloneNotSupportedException {
return (B)super.clone();
}
}
static class C extends B{
int k=3;
@Override
protected C clone() throws CloneNotSupportedException {
return (C)super.clone();
}
}
public static void main(String[] args) throws CloneNotSupportedException {
A a = new CloneTest.A();
A aa = (A) a.clone();
System.out.println("before clone a.i = "+ a.i+" after clone aa.i=" +aa.i);
B b = new CloneTest.B();
B bb= (B) b.clone();
System.out.println("before clone b.j = "+ b.j+" after clone bb.j=" +bb.j);
C c = new CloneTest.C();
C cc= (C) c.clone();
System.out.println("before clone c.k = "+ c.k+" after clone cc.k=" +cc.k);
}
}
程序如下:
--------------------------------------------------------------
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.FileNotFoundException;
public class copy {
public static void main (String args[]) {
if (args.length 2) {
System.out.println("請(qǐng)按以下格式輸入:java copy 原路徑 目標(biāo)路徑");
return;
}
try {
FileReader reader = new FileReader(args[0]);
FileWriter writer = new FileWriter(args[1]);
int c = -1;
while ((c = reader.read()) != -1)
writer.write(c);
reader.close();
writer.close();
} catch (FileNotFoundException fnfe) {
System.out.println("原文件不存在!");
return;
} catch (IOException ioe) {
System.out.println("拷貝失??!");
return;
}
System.out.println("拷貝成功!");
}
}
-----------------------------------------------------------------
運(yùn)行程序時(shí)輸入如下命令:
java copy 原文件路徑 新文件路徑
-----------------------------------------------------------------
截圖如下: