| /* This code reads from an existing file inFile.txt in the folder MyFolder on the C drive and writes the input to a second file outFile.txt in that folder. */ i import java.io.IOException;
class Test { public static void main( String args[] ) throws FileNotFoundException,IOException { FileInputStream pfis = new FileInputStream("C:/MyFolder/inFile.txt"); FileOutputStream pfos = new FileOutputStream( "C:/MyFolder/outFile.txt" );
byte[] buff = new byte[256]; int len; while( (len = pfis.read(buff)) > 0 ) { pfos.write(buff,0,len); } pfos.flush(); pfos.close(); pfis.close(); } } |