本帖最后由 java2000_net 于 2008-09-29 15:24:30 编辑

解决方案 »

  1.   

    FileInputStream   fis   =   new   FileInputStream( "C:/aaa/test.txt "); 
    FileOutputStream   fos   =   new   FileOutputStream( "C:/bbb/test.txt "); 
    byte[]   buff   =   new   byte[1024]; 
    int   readed   =   -1; 
    while((readed   =   fis.read(buff))   >   0) 
        fos.write(buff,   0,   readed); 
    fis.close(); 
    fos.close();
      

  2.   

    To read all the lines in a file and write to another file, is it count?
      

  3.   

            FileChannel inChannel = new FileInputStream(in).getChannel();
            FileChannel outChannel = new FileOutputStream(out).getChannel();
            try {
                inChannel.transferTo(0, inChannel.size(), outChannel);
            } 
            catch (IOException e) {
                throw e;
            }
      

  4.   

    Method to read a file:
    public static String readFile(String fileName) { 
            String output = "";  
             
            File file = new File(fileName); 
                
            if(file.exists()){ 
                if(file.isFile()){ 
                    try{ 
                        BufferedReader input = new BufferedReader (new FileReader(file)); 
                        StringBuffer buffer = new StringBuffer(); 
                        String text; 
                            
                        while((text = input.readLine()) != null) 
                            buffer.append(text +"\n"); 
                            
                        output = buffer.toString();                     
                    } 
                    catch(IOException ioException){ 
                        System.err.println("File Error!");                 } 
                } 
                else if(file.isDirectory()){ 
                    String[] dir = file.list(); 
                    output += "Directory contents:\n"; 
                     
                    for(int i=0; i<dir.length; i++){ 
                        output += dir[i] +"\n"; 
                    } 
                } 
            } 
            else{ 
                System.err.println("Does not exist!"); 
            } 
            return output; 
         } 
      

  5.   

    使用JDK就行,这里的JNI是自己重写一个JNI的方法而已。
      

  6.   

    Runtime.getRuntime().exec(<copy command string>)
      

  7.   

    It's not using JDK, I think. Because the copy method will invoke Windows' methods...
      

  8.   

    FileOutputStream out = new FileOutputStream(file, true);
    java.io.FileReader fileReaderObj = new java.io.FileReader("D:\\2\\5.txt");
    BufferedReader bufferedReaderObj = new BufferedReader(fileReaderObj);
    while ((strVal = bufferedReaderObj.readLine()) != null) {
    out.write(strVal.getBytes("GB2312"));}
      

  9.   

    File file = new File("C:\\Documents and Settings\\1212.doc");
    if (!file.exists()) {
    file.createNewFile();
    }
    FileOutputStream out = new FileOutputStream(file, true);
    StringBuffer sb = new StringBuffer();
    java.io.FileReader fileReaderObj = new java.io.FileReader("C:\\Documents and Settings\\1.txt");
    BufferedReader bufferedReaderObj = new BufferedReader(fileReaderObj);
    while ((strVal = bufferedReaderObj.readLine()) != null) {
    sb.append(strVal);
    }
    out.write(sb.toString().getBytes("UTF-8"));
    out.close();
      

  10.   

    byte[] buff = new byte[1024]; 
    boolean cont = true; // 循环控制变量 
    FileOutputStream outfile = null; // 文件输出对象 // 生成对象outfile,准备输出到文件 
    try 

    outfile = new FileOutputStream(args[0]); 

    catch (FileNotFoundException e) 

    System.err.println("文件不存在"); 
    System.exit(1); 
    } // 行首没有输入句号时执行如下循环 
    while (cont) 

    try 

    int n = System.in.read(buff); // 从System.in读入数据 
    System.out.write(buff, 0, n); // 写入到System.out中 
    if (buff[0]==&acute;#&acute;) 

    cont = false; 

    else 

    outfile.write(buff, 0, n); 
      

  11.   

    这个方法也可以呀,都是用文件流实现的复制,不知道还有没有别的复制方式了/**以文件流的方式复制文件
         * @param src 文件源目录
         * @param dest 文件目的目录
         * @throws IOException  
        */public void copyFile(String src,String dest) throws IOException...{
            FileInputStream in=new FileInputStream(src);
            File file=new File(dest);
            if(!file.exists())
                file.createNewFile();
            FileOutputStream out=new FileOutputStream(file);
            int c;
            byte buffer[]=new byte[1024];
            while((c=in.read(buffer))!=-1)...{
                for(int i=0;i<c;i++)
                    out.write(buffer[i]);        
            }
            in.close();
            out.close();
    }
      

  12.   

    long start = System.currentTimeMillis();
    FileChannel inChannel = new FileInputStream("C:/ntldr").getChannel();
    FileChannel outChannel = new FileOutputStream("C:/ntldr.bak").getChannel();
    inChannel.transferTo(0, Integer.MAX_VALUE, outChannel);
    inChannel.close();
    outChannel.close();
    long end = System.currentTimeMillis();
    System.out.println("transfer over, spend time : " + (end - start) + " ms.");
      

  13.   

    或者说你是指arraycopy(复制数组)那种?
      

  14.   


    class Student implements Cloneable
    {
        String name;
        int age;
        Student(String name,int age)
        {
            this.name=name;
            this.age=age;
        }
        public Object clone()
        {
            Object o=null;
            try
            {
            o=(Student)super.clone();
            }
            catch(CloneNotSupportedException e)
            {
                System.out.println(e.toString());
            }
            return o;
        }
    }
     
    public static void main(String[] args)
        {
          Student s1=new Student("a",1);
          Student s2=(Student)s1.clone();
          s2.name="";
         s2.age=20;
    System.out.println("name="+s1.name+","+"age="+s1.age);//修改学生2后,不影响学生1的值。
       }这种?