Created
March 4, 2018 13:10
-
-
Save anikseu/a366b9432f2fae0be631889487579280 to your computer and use it in GitHub Desktop.
File Copy using Java I/O
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * CSE 2015 - Programming Language II (KMH) | |
| * Homework - March 5, 2018 | |
| */ | |
| import java.io.FileNotFoundException; | |
| import java.io.IOException; | |
| import java.io.RandomAccessFile; | |
| /** | |
| * | |
| * @author th3an | |
| */ | |
| public class JavaApplication3 { | |
| /** | |
| * @param args the command line arguments | |
| */ | |
| public static void main(String[] args) throws IOException { | |
| String mainFile = "one.txt"; | |
| String newFile = "two.txt"; | |
| copyNow(mainFile, newFile); | |
| } | |
| private static void copyNow(String mainFile, String newFile) throws FileNotFoundException, IOException { | |
| RandomAccessFile data1 = new RandomAccessFile(mainFile, "rw"); | |
| RandomAccessFile data2 = new RandomAccessFile(newFile, "rw"); | |
| data2.seek(0); | |
| long length=data1.length(); | |
| for(int i=0; i<length; i++){ | |
| data2.write(data1.read()); | |
| } | |
| data1.close(); | |
| data2.close(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment