package demo; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class App { public static void main(String[] args) { String pathname ="C:\Users\Administrator\Desktop\888.sql";//设置文件路径 File file = new File(pathname);//读取文件到内存 try { OutputStream out =new FileOutputStream("h:\889.sql");//获得文件输出流 InputStream in = new FileInputStream(file);//获得文件输入流 byte[] buffer = new byte[1024];//设置写入数组大小 int length =-1; while((length = in.read(buffer))!=-1) {//方法把读取到的数据赋值给参数 out.write(buffer, 0, length);//以二进制写入文件到磁盘直到写入完毕 } } catch (IOException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } } }