试写一下
import java.io.*;
import java.nio.channels.*;public class TransferTo {
public static void main(String[] args) {
try {

FileChannel in_1 = new FileInputStream("1.txt").getChannel();
FileChannel in_2=new FileInputStream("2.txt").getChannel();
FileChannel out = new FileOutputStream("3.txt").getChannel();
in_1.transferTo(0, in_1.size(), out);
in_2.transferTo(0, in_2.size(), out);
System.out.println("have created a file named "+"'3.txt'");
} catch (Exception e) {
System.out.println("Catch===>" + e);
      }
}
      }

解决方案 »

  1.   

    试试这个,呵呵
    import java.io.*;
    public class ReadFileTest{
    public static void main(String[] args){
    char[] mych = ReadF("e:\\readjava.txt");
    for (int i=0;i<mych.length;i++){
    System.out.print(mych[i]);
    }
        
    }
     private static char[] ReadF(String filename){
    try{
        File file = new File(filename);
            Reader rdr = new FileReader( file );
            long sz = file.length();
            // can only read in things of MAXINT length
            char[] ch = new char[(int)sz];          rdr.read(ch);
            rdr.close();
           //System.out.println(ch);
           //return new String(ch);
           return ch;
      }catch(IOException e){
       return null;
      }
    }
    static public boolean saveFile(String filename, String contents) {
        try {
            File file = new File( filename );
            if(file.getParent() != null) {
                  new File(file.getParent()).mkdirs();
            }
            Writer wtr = new FileWriter( file );
            char[] ch = contents.toCharArray();
            wtr.write(ch);
            wtr.close();
            return true;
        } catch(IOException ioe) {
            return false;
        }

    }