Discuss / Java / 交作业啦

交作业啦

Topic source

王能能Lily

#1 Created at ... [Delete] [Delete and Lock User]

public class CopyFile {

public static void main(String[] args) throws IOException {

copy("F:\\testDemo.txt", "F:\\testDemo3.txt");

}

static void copy(String source, String target) throws IOException {

byte[] b=new byte[2000];

try(InputStream inputStream =new FileInputStream(source)){

try(OutputStream outputStream=new FileOutputStream(target)){

if ( (inputStream.read(b))!=-1) {

outputStream.write(b);

}

}

}

}

}


  • 1

Reply