Copy of Java------files

Source: Internet
Author: User

Import Java.io.fileinputstream;import Java.io.filenotfoundexception;import Java.io.fileoutputstream;import Java.io.ioexception;public class Filecopystream {public static void main (string[] args) {//filecopy0 ("B.dat", "d:/ex/a/ "," d:/ex/b/"),//filecopy1 (" B.dat "," d:/ex/a/"," d:/ex/b/"),//filecopy2 (" B.dat "," d:/ex/a/"," d:/ex/b/"); FileCopy2 ( "1.mp3", "d:/ex/a/", "d:/ex/b/"),//filecopy3 ("C.mp3", "d:/ex/a/", "d:/ex/b/"),//filecopy3 ("D.txt", "d:/ex/a/", "d:/ ex/b/");} private static void FileCopy0 (String fileName, String dir1,string dir2) {try {fileinputstream in = new FileInputStream (dir1 +filename); FileOutputStream out = new FileOutputStream (dir2+filename); byte[] buffer = new Byte[512];in.read (buffer); Out.write ( buffer);} catch (FileNotFoundException e) {e.printstacktrace ()} catch (Exception e) {}}//learn mathematic private static void FileCopy1 (String FileName, String dir1,string dir2) {fileinputstream in = null; FileOutputStream out = null;try {in = new FileInputStream (dir1+filename), out = new FileOutputStream (dir2+fiLename); byte[] buffer = new Byte[512];in.read (buffer); out.write (buffer); catch (FileNotFoundException e) {e.printstacktrace ();} catch (Exception e) {}finally{try {in.close (); Out.close ();} catch (IOException e) {throw new RuntimeException ("File cannot be closed");}}} Ability to copy large file private static void FileCopy2 (String fileName, String dir1,string dir2) {fileinputstream in = null; FileOutputStream out = null;try {in = new FileInputStream (dir1+filename), out = new FileOutputStream (dir2+filename); byte[ ] buffer = new Byte[512];int num = 0;do{num = in.read (buffer); Out.write (buffer,0,num);} while (num>=0);} catch (FileNotFoundException e) {e.printstacktrace ();} catch (Exception e) {e.printstacktrace ();} Finally{try {in.close (); Out.close ();} catch (IOException e) {throw new RuntimeException ("File cannot be closed");}} Ability to copy large file private static void FileCopy3 (String fileName, String dir1,string dir2) {fileinputstream in = null; FileOutputStream out = null;try {in = new FileInputStream (dir1+filename), out = new FileOutputStream (Dir2+filenAME); byte[] buffer = new Byte[512];int Num=0;while (in.available () >0) {num = in.read (buffer);//simplest encryption for (int i=0;i <num;i++) {Buffer[i] = (byte) (buffer[i]+1);} Out.write (Buffer,0,num);}} catch (FileNotFoundException e) {e.printstacktrace ();} catch (Exception e) {}finally{try {in.close (); Out.close ();} catch (IOException e) {throw new RuntimeException ("File cannot be closed");}}}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Copy of Java------files

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.