`
- 浏览:
51897 次
- 性别:
- 来自:
南宁
-
- import java.io.*;
- import java.text.*;
- import java.util.*;
- public class CopyFile {
- public static void main(String[] args) throws IOException {
- new CopyFile().copy(args[0], args[1], Integer.parseInt(args[2]));
- }
- public int copy(String source_name, String dest_name, int type)
- throws IOException {
- File source_file = new File(source_name);
- File dest_file = new File(dest_name);
- FileInputStream source = null;
- FileOutputStream destination = null;
- byte[] buffer;
- int bytes_read;
- int result = 0;
- try {
- if (!source_file.exists() || !source_file.isFile())
- throw new RuntimeException("FileCopy: no such source file: "
- + source_name);
- if (!source_file.canRead())
- throw new RuntimeException("FileCopy: source file "
- + "is unreadable: " + source_name);
- if (dest_file.exists()) {
- if (dest_file.isFile()) {
- if (type == 1)
- {
- dest_file.delete();
- result = 1;
- } else
- {
- result = 2;
- return result;
- }
- } else
- throw new RuntimeException("FileCopy: destination "
- + "is not a file: " + dest_name);
- } else {
- File parentdir = new File(dest_file.getParent());
- if (!parentdir.exists())
- throw new RuntimeException("FileCopy: destination "
- + "directory doesn't exist: " + dest_name);
- if (!parentdir.canWrite())
- throw new RuntimeException("FileCopy: destination "
- + "directory is unwriteable: " + dest_name);
- }
-
- source = new FileInputStream(source_file);
- destination = new FileOutputStream(dest_file);
- buffer = new byte[1024];
- while (true) {
- bytes_read = source.read(buffer);
- if (bytes_read == -1) {
- break;
- }
- destination.write(buffer, 0, bytes_read);
- }
- } finally {
- if (source != null) {
- try {
- source.close();
- } catch (IOException e) {
- }
- }
- if (destination != null) {
- try {
- destination.close();
- } catch (IOException e) {
- }
- }
- return result;
- }
- }
分享到:
Global site tag (gtag.js) - Google Analytics
相关推荐
jdk6.0学习笔记 jdk学习笔记 java学习 web编程
良葛格 java jdk 6.0 学习笔记
Java JDK 6.0学习笔记,通俗易懂很适合初学者了解java中的要点。。。。。。
最新的Java JDK6.0课件及源代码,初学Java的朋友不要错过
Java学习笔记 入门准备 接触物件 物件向导 资源管理 物件容器 输入输出 執行緒 反射 metadata 资料库 拾遗补缺 视窗程式 参考资料
相当不错的一本电子书 彩色的PDF
这个是最基础的JAVA学习资料,我个人觉得还可以,有源码,课件.....在此和大家共享....
J2SDK1.6学习笔记PPT版,详细讲解JAVA的基础知识,特别适合初学者学习。
良葛格java学习笔记,分享作者林信良的学习经验,更新JDK6.0新特性
java学习笔记JDK6课件和课本代码特别适合Java初学者,它比以前那个什么Java学习笔记更加全面,希望对各位有用,不足之处还请指出,谢谢合作!!
6、发布个人学习笔记,并对学习笔记进行维护; 7、支付宝在线支付接口,实现在线购买服务功能; 8、个人信息管理,个人界面方案维护; 9、信息反馈及维护; 10、JavaMail邮件发送功能实现。 项目演示地址:...
6、发布个人学习笔记,并对学习笔记进行维护;7、支付宝在线支付接口,实现在线购买服务功能;8、个人信息管理,个人界面方案维护;9、信息反馈及维护;10、JavaMail邮件发送功能实现。各功能模块的稳定性都经过了...
Jdk 1.4, jdk 1.5(5.0), jdk 1.6(6.0) jdk 1.5(5.0):Tiger,老虎 jdk 1.6(6.0):Mustang,野马 1. 下载JDK 2. 安装JDK 3. 设定环境变量(可以是用户变量,也可以是系统变量),指向JDK 安装目录中 的bin ...
《韩顺平linux视频全部资料》其中jdk 6.0.iso 68, 68.5MB、eclipse-SDK-3.7-linux-gtk-x86_64.tar.gz 174MB、MyEclipseEnterpriseWorkbench.5.1.0GA.linux.tar.gz 118MB资源太大,无法上传,主要是由于上传权限被...
火龙果软件工程技术中心 相关资料:《jBPM学习笔记(流程设计与控制)》《jBPM学习笔记(框架设计简介)》系统平台:系统环境:Windows2003|SUNJDK1.6U4|Tomcat6.0.14|jbpm-starters-kit-3.1.4|MySQL6.0主机完整名称:...