189 8069 5689

java运行拷贝的代码 java 拷贝

怎样用java程序实现文件拷贝

通过输入输出流解决此问题,具体的可以查看JDK的API,实在不会的话,百度一下应该都有一堆这方面的代码。

创新互联公司于2013年创立,是专业互联网技术服务公司,拥有项目成都网站设计、成都网站建设网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元沂南做网站,已为上家服务,为沂南各地企业和个人服务,联系电话:18980820575

java 代码实现对象的拷贝

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);

}

}

java编程 编写一个文件拷贝的程序

程序如下:

--------------------------------------------------------------

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("请按以下格式输入:java copy 原路径 目标路径");

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("拷贝成功!");

}

}

-----------------------------------------------------------------

运行程序时输入如下命令:

java copy 原文件路径 新文件路径

-----------------------------------------------------------------

截图如下:


本文名称:java运行拷贝的代码 java 拷贝
网页地址:http://jkwzsj.com/article/ddohihs.html

其他资讯