我来解释一下
就是生成三个文件
先是写上那三个文件
后做把第一第二加上第三
n 时就用cat加在后面
y 时就用cat覆盖

解决方案 »

  1.   

    import   java.io.*;
    import   java.awt.*;
    import   java.awt.event.*;public  class  filework{
    public static void copy(InputStream in,OutputStream out) throws IOException{
                        byte[]  buf=new  byte[1024];
                        int  len=in.read(buf);
                        while(len!=-1){
                                 out.write(buf,0,len);
                                 len=in.read(buf);
                        }
             }
     
             public  static  void  overwritecat(String str1,String str2,String str3){
                        try{
                                 InputStream   in1=new   FileInputStream(str1);
                                 OutputStream   out1=new   FileOutputStream(str2);
                                 copy(in1,out1);
                                 in1.close();
                                 out1.close();
                                 InputStream   in2=new   FileInputStream(str2);
                                 OutputStream   out2=new   FileOutputStream(str3,true);
                                 copy(in2,out2);
                                 in2.close();
                                 out2.close();
                          }catch(IOException  e){
                                  System.out.println(e);
                          }
            }
            
           public  static  void  cat(String str1,String str2,String str3){
                        try{
                                 InputStream   in1=new   FileInputStream(str1);
                                 OutputStream   out1=new   FileOutputStream(str2);
                                 copy(in1,out1);
                                 in1.close();
                                 out1.close();
                                 InputStream   in2=new   FileInputStream(str2);
                                 OutputStream   out2=new   FileOutputStream(str3);
                                 copy(in2,out2);
                                 in2.close();
                                 out2.close();
                          }catch(IOException  e){
                                  System.out.println(e);
                          }
                        }
    public  static  void  main(String args[]) throws IOException { 
             System.out.println("please intput the first file");
             byte  buffer1[]=new   byte[20];
             System.in.read(buffer1,0,20);
                // String  str1=new  String(buffer1);
             File  file1=new  File("e:/javacode/str1.txt");
             boolean  t1=file1.isFile();
             if(t1==false)
             System.out.println("file1 is no exited");         System.out.println("please intput the second file");
             byte  buffer2[]=new   byte[20];
             System.in.read(buffer2,0,20);
             String  str2=new  String(buffer2);
             File  file2=new  File("e:/javacode/str2.txt");
             boolean  t2=file2.isFile();
             if(t2==false)
             System.out.println("file2 is no exited");         System.out.println("please intput the thrid file");
             byte  buffer3[]=new   byte[20];
             System.in.read(buffer3,0,20);
             String  str3=new  String(buffer2);
              File  file3=new  File("e:/javacode/str3.txt");
      //       File  file3=new  File("str3");
             boolean  t3=file3.isFile();
             if(t3==false)
                        System.out.println("file3 is no exited");
             else{
                        System.out.println("you are should you overwrited n/y");
                        String  ch="";
                        StreamTokenizer tokenizer =new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
                        int j=tokenizer.nextToken();
                        if(j==tokenizer.TT_WORD){
                         ch=tokenizer.sval;}
                        if(ch.equals("n")){
                               cat("e:/javacode/str1.txt","e:/javacode/str2.txt","e:/javacode/str3.txt");
                               System.out.println("sucess!")                      
                        }
                        if(ch.equals("y")){
                               overwritecat("e:/javacode/str1.txt","e:/javacode/str2.txt","e:/javacode/str3.txt");
                               System.out.println("sucessoverwrite!");   
                        }            
             }
             
              }
    }
      

  2.   

    import   java.io.*;
    import   java.awt.*;
    import   java.awt.event.*;public  class  filework{
    public static void copy(InputStream in,OutputStream out) throws IOException{
                        byte[]  buf=new  byte[1024];
                        int  len=in.read(buf);
                        while(len!=-1){
                                 out.write(buf,0,len);
                                 len=in.read(buf);
                        }
             }
     
             public  static  void  overwritecat(String str1,String str2,String str3){
                        try{
                                 InputStream   in1=new   FileInputStream(str1);
                                 OutputStream   out1=new   FileOutputStream(str2);
                                 copy(in1,out1);
                                 in1.close();
                                 out1.close();
                                 InputStream   in2=new   FileInputStream(str2);
                                 OutputStream   out2=new   FileOutputStream(str3,true);
                                 copy(in2,out2);
                                 in2.close();
                                 out2.close();
                          }catch(IOException  e){
                                  System.out.println(e);
                          }
            }
            
           public  static  void  cat(String str1,String str2,String str3){
                        try{
                                 InputStream   in1=new   FileInputStream(str1);
                                 OutputStream   out1=new   FileOutputStream(str2);
                                 copy(in1,out1);
                                 in1.close();
                                 out1.close();
                                 InputStream   in2=new   FileInputStream(str2);
                                 OutputStream   out2=new   FileOutputStream(str3);
                                 copy(in2,out2);
                                 in2.close();
                                 out2.close();
                          }catch(IOException  e){
                                  System.out.println(e);
                          }
                        }
    public  static  void  main(String args[]) throws IOException { 
             System.out.println("please intput the first file");
             String  str1;
             BufferedReader inn1=new BufferedReader(new InputStreamReader(System.in));
             str1=inn1.readLine();
             File  file1=new  File(str1);
             boolean  t1=file1.isFile();
             if(t1==false)
             System.out.println(str1+" is no exsited");         System.out.println("please intput the second file");
              String  str2;
             BufferedReader inn2=new BufferedReader(new InputStreamReader(System.in));
             str2=inn2.readLine();
             File  file2=new  File(str2);
             boolean  t2=file2.isFile();
             if(t2==false)
             System.out.println(str2+" is no exited");         System.out.println("please intput the thrid file");
             String  str3;
             BufferedReader inn3=new BufferedReader(new InputStreamReader(System.in));
             str3=inn3.readLine();
             File  file3=new  File(str3);
             boolean  t3=file3.isFile();
             if(t3==false)
                        System.out.println(str3+" is no exited");
             else{
                        System.out.println("you are should you overwrited n/y");
                        String  ch="";
                        StreamTokenizer tokenizer =new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
                        int j=tokenizer.nextToken();
                        if(j==tokenizer.TT_WORD){
                         ch=tokenizer.sval;}
                        if(ch.equals("n")){
                               cat(str1,str2,str3);
                               System.out.println("sucess!");                      
                        }
                        if(ch.equals("y")){
                               overwritecat(str1,str2,str3);
                               System.out.println("sucessoverwrite!");   
                        }            
                }
             
         }
    }
      

  3.   

    import   java.io.*;
    import   java.awt.*;
    import   java.awt.event.*;public  class  filework{
    public static void copy(InputStream in,OutputStream out) throws IOException{
                        byte[]  buf=new  byte[1024];
                        int  len=in.read(buf);
                        while(len!=-1){
                                 out.write(buf,0,len);
                                 len=in.read(buf);
                        }
             }
     
             public  static  void  overwritecat(String str1,String str2,String str3){
                        try{
                                 InputStream   in1=new   FileInputStream(str1);
                                 OutputStream   out1=new   FileOutputStream(str2);
                                 copy(in1,out1);
                                 in1.close();
                                 out1.close();
                                 InputStream   in2=new   FileInputStream(str2);
                                 OutputStream   out2=new   FileOutputStream(str3,true);
                                 copy(in2,out2);
                                 in2.close();
                                 out2.close();
                          }catch(IOException  e){
                                  System.out.println(e);
                          }
            }
            
           public  static  void  cat(String str1,String str2,String str3){
                        try{
                                 InputStream   in1=new   FileInputStream(str1);
                                 OutputStream   out1=new   FileOutputStream(str2);
                                 copy(in1,out1);
                                 in1.close();
                                 out1.close();
                                 InputStream   in2=new   FileInputStream(str2);
                                 OutputStream   out2=new   FileOutputStream(str3);
                                 copy(in2,out2);
                                 in2.close();
                                 out2.close();
                          }catch(IOException  e){
                                  System.out.println(e);
                          }
                        }
    public  static  void  main(String args[]) throws IOException { 
             System.out.println("please intput the first file");
             String  str1;
             BufferedReader inn1=new BufferedReader(new InputStreamReader(System.in));
             str1=inn1.readLine();
             File  file1=new  File(str1);
             boolean  t1=file1.isFile();
             if(t1==false)
             System.out.println(str1+" is no exsited");         System.out.println("please intput the second file");
              String  str2;
             BufferedReader inn2=new BufferedReader(new InputStreamReader(System.in));
             str2=inn2.readLine();
             File  file2=new  File(str2);
             boolean  t2=file2.isFile();
             if(t2==false)
             System.out.println(str2+" is no exited");         System.out.println("please intput the thrid file");
             String  str3;
             BufferedReader inn3=new BufferedReader(new InputStreamReader(System.in));
             str3=inn3.readLine();
             File  file3=new  File(str3);
             boolean  t3=file3.isFile();
             if(t3==false)
                        System.out.println(str3+" is no exited");
             else{
                        System.out.println("you are should you overwrited n/y");
                        String  ch="";
                        StreamTokenizer tokenizer =new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
                        int j=tokenizer.nextToken();
                        if(j==tokenizer.TT_WORD){
                         ch=tokenizer.sval;}
                        if(ch.equals("n")){
                               cat(str1,str2,str3);
                               System.out.println("sucess!");                      
                        }
                        if(ch.equals("y")){
                               overwritecat(str1,str2,str3);
                               System.out.println("sucessoverwrite!");   
                        }            
                }
             
         }
    }