Discuss / Java / test

.

#1 Created at ... [Delete] [Delete and Lock User]
import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;
public class TestCopy {
    public static void main(String[] args) throws IOException {
        String source = "source.txt";        String copy = "copy.txt";        TestCopy c = new TestCopy();        c.Copyfile(source,copy);    }
        public static void Copyfile (String source, String copy){
            try (InputStream input = new FileInputStream(source);                 final OutputStream output = new FileOutputStream(copy)) {

                input.transferTo(output); // transferTo                System.out.println("拷贝成功!");            } catch (IOException e) {

                System.out.println("Exception encountered: " + e);            }
        }

  • 1

Reply