很简单的小问题,求各位帮忙解决一下啦~(有分的!)

dingwenyuan 2003-03-21 02:09:48
import java.io.*;

public class Copy {
public static void main(String[] args) {
if(args.length < 2) {
System.out.println("Usage: Copy[Source Filename][Object Filename].");
}
else {
File fSource = new File(args[0]);
boolean isOK = true;
//判断源文件是否存在
if(!fSource.exists()) {
System.out.println("Source File" + args[0] + "is not a exists!");
isOK = false;
}
//判断源文件是否是文件,而不是目录
if(isOK && !fSource.isFile()) {
System.out.println("Source File" + "Source File" + args[0] + " !");
}
File fObject = new File(args[1]);
try {
//判断目标文件是否存在,如果存在是否覆盖
if(isOK && fObject.exists()) {
System.out.println("Object File" + args[0] + "is already exists!");
System.out.print("Overwrite?y/n");
int ch = System.in.read();
if(ch == 'n' || ch == 'N') {
isOK = false;
}
}
if(isOK) {
FileInputStream fisSource = new FileInputStream(args[0]);
FileOutputStream fosObject = new FileOutputStream(args[1]);
System.out.println("Copy file from" + args[0] + "to" + args[1] + "……");
while(fisSource.available() > 0) {
int temp = fisSource.read();
fosObject.write(temp);
}
fisSource.close();
fosObject.close();
System.out.println("File Copyed Successfully!");
}
}
catch(IOException e) {
System.out.println(e);
}
}
}
}

这是一个实现文件copy的程序,但我不知道到要拷贝的文件的文件名,以及路径应该怎么添加进去啊..
...全文
26 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
foolbirds 2003-03-21
  • 打赏
  • 举报
回复
怎样结贴:
http://expert.csdn.net/Expert/TopicView1.asp?id=1131170
dingwenyuan 2003-03-21
  • 打赏
  • 举报
回复
真是太谢谢了,小弟刚开始学,有点懵住了,呵呵,知道了..
十分感谢各位,怎么把分给你吗啊,我刚来这里不久!
foolbirds 2003-03-21
  • 打赏
  • 举报
回复
通过args[0]和args[1]来定位
bubblebird 2003-03-21
  • 打赏
  • 举报
回复
没讲的了
foolbirds 2003-03-21
  • 打赏
  • 举报
回复
java Copy sourceFile newFile
bluesmile979 2003-03-21
  • 打赏
  • 举报
回复
你不是用命令好参数的么?

java Copy sourceFile copyedFile

62,616

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧