Package COM. neusoft. mytest. myproj; 002 003 import Java. io. *; 004 005 import Java. io. file; 006 007/** 008 * @ author ultimate scholar copying Objects Based on byte streams 009*010 */011 public class bytecopy {012 013 public static void main (string [] ARGs) {014 file f_s = new file ("G:/wjl/jizhishusheng.txt"); // file object to be copied 015 file f_d = new file ("D:/yxm "); // path 016 if (! F_d.exists () {// determine whether the path to be copied exists. If it does not exist, create 017 f_d.mkdirs (); 018 019} 020 file f_dd = new file (f_d, "7s.txt"); 021 fileinputstream FCM = NULL; 022 fileoutputstream Fos = NULL; 023 try {024 FD = new fileinputstream (f_s); 025 Fos = new fileoutputstream (f_dd ); 026 byte [] bytetemp = new byte [1024]; 027 while (FCM. read (bytetemp )! =-1) {028 int size = bytetemp. length; 029 FOS. write (bytetemp, 0, size); 030 031} 032} catch (filenotfoundexception e) {033 E. printstacktrace (); 034} catch (ioexception e) {035 E. printstacktrace (); 036} 037 finally {038 try {039 if (FS! = NULL) {040 FOS. Close (); 041 042} 043 if (FOS! = NULL) {044 FS. close (); 045 046} 047} catch (ioexception e) {048 E. printstacktrace (); 049} 050 051} 052 053} 054 055} 056 057 058 package COM. neusoft. mytest. myproj; 059 060 import Java. io. *; 061 062 import Java. io. file; 063 064/** 065 * @ author extreme scholar copy of files implemented based on the ghost stream 066*067 */068 public class charcopy {069 070 public static void main (string [] ARGs) {071 file f_s = new file ("G:/wjl/jizh Ishusheng.txt "); // object to be copied 072 file f_d = new file (" D:/yxm "); // path 073 if (! F_d.exists () {// determine whether the path to be copied exists. If it does not exist, create 074 f_d.mkdirs (); 075 076} 077 file f_dd = new file (f_d, "7s.txt"); 078 filereader FCM = NULL; 079 filewriter Fos = NULL; 080 try {081 FCM = new filereader (f_s); 082 Fos = new filewriter (f_dd ); 083 char [] chartemp = new char [1]; 084 while (FCM. read (chartemp )! =-1) {085 int size = chartemp. length; 086 FOS. write (chartemp, 0, size); 087} 088} catch (filenotfoundexception e) {089 E. printstacktrace (); 090} catch (ioexception e) {091 E. printstacktrace (); 092} finally {093 try {094 if (FS! = NULL) {095 FOS. Close (); 096 097} 098 if (FOS! = NULL) {099 FCM. Close (); 100 101} 102} catch (ioexception e) {103 e. printstacktrace (); 104} 105 106} 107 108} 109 110}