怎样复制文件? 将file1.txt复制到file2.txt中,源文件名和目标文件名作为命令行参数输入请问怎么实现? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public static void main(String[] args) throws Exception { String from_file = args[0]; String to_file = args[1]; BufferedInputStream in = new BufferedInputStream(new FileInputStream(from_file)); BufferedOutputStream out = new BufferedOutputStream(new OutputStream(to_file)); int n = in.read(); while(n != -1) { out.write(n); n = in.read(); } in.close(); out.close();} import java.io.*;public class FileTest{ public static void main(String[] args) { Inter am=new Inter(); if(args.length==0) { System.out.println("请输入文件名!"); return; } try{ am.show(args[0],args[1]); }catch(Exception e) { System.out.println(e.getMessage()); } }}class Inter{ String line=""; public void show(String filename1,String filename2)throws Exception { FileReader f=new FileReader(filename1); BufferedReader m=new BufferedReader(f); FileWriter f1=new FileWriter(filename2); BufferedWriter m1=new BufferedWriter(f1); do { line=m.readLine(); m1.write(line); m1.newLine(); }while(line!=null); //关闭文件 m.close(); f.close(); m1.close(); f1.close(); System.out.println("文件复制完成!"); } }怎么最后显示是null?请问我这个有什么问题? java nio 文件写入 nio的selector.open()为什么不能立即返回? 怎样提取行汉字的首字母如:阿光,则提取A出来! 如何利用ESC键,退出对话框 JCREATOR遇到问题 Applet的问题 jvm的内存原理(方法区和常量池)??? 征询学C#与学JAVA哪个好学些? 用JAVAMAIL发送带文件名带汉字的附件时,提示“系统找不到指定的文件” java大师,如何用Java编写一个socket tool工具 jsp做服务器端,.net做客户端的应用程序,能够实现吗? 如何用java实现进程的同步与等待?
String from_file = args[0];
String to_file = args[1];
BufferedInputStream in = new BufferedInputStream(new FileInputStream(from_file));
BufferedOutputStream out = new BufferedOutputStream(new OutputStream(to_file));
int n = in.read();
while(n != -1) {
out.write(n);
n = in.read();
}
in.close();
out.close();
}
{
public static void main(String[] args)
{
Inter am=new Inter();
if(args.length==0)
{
System.out.println("请输入文件名!");
return;
}
try{
am.show(args[0],args[1]);
}catch(Exception e)
{
System.out.println(e.getMessage());
}
}
}
class Inter
{
String line="";
public void show(String filename1,String filename2)throws Exception
{
FileReader f=new FileReader(filename1);
BufferedReader m=new BufferedReader(f);
FileWriter f1=new FileWriter(filename2);
BufferedWriter m1=new BufferedWriter(f1);
do
{
line=m.readLine();
m1.write(line);
m1.newLine();
}while(line!=null);
//关闭文件
m.close();
f.close();
m1.close();
f1.close();
System.out.println("文件复制完成!");
}
}
怎么最后显示是null?请问我这个有什么问题?