Portal Home > Knowledgebase > Articles Database > code to transfer data of one file to another file
code to transfer data of one file to another file
Posted by alisha0512, 06-16-2008, 06:40 AM |
please tell me the code to transfer data of one file to another existing fie in any programming language.
|
Posted by Steve_Arm, 06-16-2008, 06:45 AM |
The easiest would be from a command shell:
cat file1 >> file2
then it depends where this will be used.
|
Posted by Saeven, 06-16-2008, 11:42 AM |
Though I agree with you Steve, the op seemed to want a programming language for some reason...
"transfer data from one file to another file" -- aka copy?
http://ca3.php.net/manual/en/function.copy.php
|
Posted by Barti1987, 06-16-2008, 12:16 PM |
Yeah sure, you want someone to write you the copy file code for ALL languages, good luck on finding such person.
Peace,
|
Posted by stdunbar, 06-16-2008, 01:47 PM |
Ok, while hardly the most popular language on WHT here is the Java implementation:
|
Posted by Saeven, 06-16-2008, 02:05 PM |
If I may interject that in practice, you should always wrap your FileInputStream in a BufferedReader to reduce the amount of lower-level IO calls.
Still not sure what the op wanted though...
|
Posted by alisha0512, 06-24-2008, 06:48 AM |
thanks for reply.
please tell me what is the work of Inputstream and Outputstream in java?
|
Posted by stdunbar, 06-24-2008, 12:12 PM |
The FileInputStream reads the file and the FileOutputStream writes the file.
Basically all that is going on is that the FileInputStream is opened on the source file - that is the file that you want to make a copy of. The FileOutputStream is opened on the destination file. In my tiny code sample it is opened for delete - if there is a destination file already it will be deleted first and then written to. The code then reads 16KB of data from the source file and writes that back out to the destination file. At the end of the process it closes both files.
|
Add to Favourites Print this Article
Also Read