日期:2014-05-20  浏览次数:20655 次

可不可以用命令行参数给出源文件跟目标文件的路径
想做一个实验,建立输入流文件与输出流文件,将源文件复制到目标文件,文件路径由命令行参数给出。可是在dos下编译成功后,运行键入源文件和目标文件路径后,却报错说找不到目标文件。

------解决方案--------------------
看不懂LZ想要什么东西,写了个程序传上来,你可以看看
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/**
*
*/

/**
* @author infon
* 2007-5-16
*/
public class Test {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
FileInputStream src=new FileInputStream(args[0]);
FileOutputStream dst=new FileOutputStream(args[1]);
//长度可调小点
byte[]buf=new byte[4*1024];
int length=0;
while((length=src.read(buf))> 0){
dst.write(buf);
}
src.close();
dst.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}