在网上找到了如下代码,经过简单的修改想把读的文件写到output中,编译后没有错误,执行后常产生了output文件,但里面是空的,没有写入。  
还有就是infile  =  new  FileInputStream(args[0]);是什么意思阿?  
不知道是什么原因,请各位帮帮忙!  
 
import  java.io.*;    
public  class  Readfile    
{    
     public  static  void  main(String[]  args)    
     {    
           byte[]  buff  =  new  byte[1024];    
           boolean  cont  =  true;    
           FileInputStream  infile  =  null;  
           try    
           {  
                 infile  =  new  FileInputStream(args[0]);  /**  ???  */  
           }  
           catch  (FileNotFoundException  e)    
           {  
                 System.err.println("error");  
                 System.exit(1);  
           }  
 
           while  (cont)    
           {  
                 try  
                 {  
 
                       int  n  =  infile.read(buff);                
                       FileOutputStream  outfile  =  new  FileOutputStream("output.txt");//!!!  
                       outfile.write(buff,  0,  n);  
 
                 }  
                 catch  (Exception  e)  
                 {  
                       cont  =  false;  
                 }  
           }  
           try    
           {  
                   infile.close();  
           }  
           catch  (IOException  e)    
           {  
                 System.err.println("error");    
                 System.exit(1);  
           }  
     }    
}

解决方案 »

  1.   

    你整个程序都没有写东西,当然txt文件是空的了```
      

  2.   

    这个程序,就是想把你的参数所指的文件,内容写到output.txt中.
    你可以用
    java Readfile.java
    这样,就可以,把Readfile.java中的内容,复制到output.txt中了!
      

  3.   

    args是main方法的参数,即是运行程序时的命令行参数,找本书看看吧
      

  4.   

    这个程序就是执行
    java Readfile input.txt
    把input.txt的内容复制到output.txt中。但问题就是执行后output.txt 中是空的,根本就没复制上。