Java 拷贝文件内容

来源:互联网 发布:asp.net源码 网络 编辑:程序博客网 时间:2024/05/21 11:25

说明:

把d盘下a.txt 中的内容复制到e盘下e.txt文件中

private static void copyDataBase() {try {File f1 = new File("d:/a.txt");File f2 = new File("e:/e.txt");InputStream in = new FileInputStream(f1);OutputStream out = new FileOutputStream(f2);byte[] buf = new byte[1024];int len;while ((len = in.read(buf)) > 0) {out.write(buf, 0, len);}in.close();out.close();System.out.println("File copied.");} catch (FileNotFoundException ex) {System.out.println(ex.getMessage() + " in the specified directory.");System.exit(0);} catch (IOException e) {System.out.println(e.getMessage());}}


0 0
原创粉丝点击