import java.io.*;class CopyFile{
public static void main(String args[])throws IOException{
int i;
FileInputStream fin = null; //定义字节文件输入流对象
FileOutputStream fout = null; //定义字节文件输出流对象
if(args.length < 2){
System.out.println("用法: CopyFile 源文件 目标文件");
return;
}
try{
fin = new FileInputStream(args[0]); //创建字节文件输入流
}catch(FileNotFoundException e){
System.out.println("源文件未找到!");
return;
}
try{
fout = new FileOutputStream(args[1]); //创建字节文件输出流
return;
}catch(FileNotFoundException e){
System.out.println("创建目标文件错误");
return;
}
try{
while((i = fin.read()) != -1) //从文件中读入一个字节
fout.write(i); //将字节写入文件中
}catch(FileNotFoundException e){
System.out.println("文件拷贝错误");
}
//关闭流
fin.close(); //无法访问的语句
fout.close(); //无法访问的语句
}
}
解决方案 »
- Java反射NoSuchMethodException问题
- 遇到一个开发问题,寻求解决办法
- 高分求解图形优化问题
- 大家会商下我目前的技术情况。。。。顶者有分。
- 关于jdbc连接与close的问题,什么情况下该使用close()?
- 求救关于jtextpane中的文本对齐
- 用JAVA一样搞3D!
- <html:file/>不能赋值,但有没有办法清空?
- 修改程序
- Math.rint(Math.random()*9)可以返回double类型的数,请问如何返回int类型的值。或者char类型的。谢谢。
- 如何修改局域网内的一台机器上的非共享文件,已知 用户名/密码
- 用DOM4j插入新元素时都要用XMLWriter把所有的元素往文件里重写一次吗?
fout = new FileOutputStream(args[1]); //创建字节文件输出流
return;
}catch(FileNotFoundException e){
System.out.println("创建目标文件错误");
return;
}这段代码你不管有没有错,都return掉了把try里的return去掉
fout.close(); //无法访问的语句
关键还是由于return的原因,你都return了,fin.close(); 就不会执行
try{
fout = new FileOutputStream(args[1]); //创建字节文件输出流
//这个 return 是多的.
// return;
}catch(FileNotFoundException e){
System.out.println("创建目标文件错误");
return;
}