473,468 Members | 1,449 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How To Copy The File

karthickkuchanur
156 New Member
Dear All ,
May i know how to copy the file from source to destination folder in java
if it is any class available in java

Or i have read the Source File from content and write it into a destination folder file
if it is any class for copying the files means it very useful for me
Nov 5 '08 #1
8 2159
r035198x
13,262 MVP
Open the API specs for the File class and check the methods there.
Nov 5 '08 #2
karthickkuchanur
156 New Member
Open the API specs for the File class and check the methods there.
There no such method to copy the file from source to destination
Nov 5 '08 #3
JosAH
11,448 Recognized Expert MVP
There no such method to copy the file from source to destination
If reading that little bit of API documentation didn't give you that tickling feeling
of curiosity to read more then programming is absolutely not for you.

kind regards,

Jos
Nov 5 '08 #4
karthickkuchanur
156 New Member
If reading that little bit of API documentation didn't give you that tickling feeling
of curiosity to read more then programming is absolutely not for you.

kind regards,

Jos
Iam more confident that iam not able to do with file class iam right
Nov 5 '08 #5
JosAH
11,448 Recognized Expert MVP
Iam more confident that iam not able to do with file class iam right
Ok, you're about sure that you can't copy a file by just using the File class. And
now what? Are you simply going to wait until somebody else takes you by the
hand and solves the problem for you? If so, programming is not for you. Go and
read the API documentation; the solution is in there; hint: FileInputStream and
FileOutputStream.

Jos
Nov 5 '08 #6
chaarmann
785 Recognized Expert Contributor
Iam more confident that iam not able to do with file class iam right
There is no ready-made method that copies a file, as far as I know.
Maybe because it's so short and easy to do it yourself.

More hints:
If you already have defined the fileInputStream and fileOutputStream and the "byte[] buffer = new byte[4096]", and "int bytesRead", then you need only 2 lines more of source code to copy the file, using a while-loop. hint: read about read() and write() methods of the streams!
Nov 5 '08 #7
r035198x
13,262 MVP
Iam more confident that iam not able to do with file class iam right
There is a method called renameTo. What does it do? How can you use it to simulate a copy in a few steps?
Nov 5 '08 #8
karthickkuchanur
156 New Member
There is no ready-made method that copies a file, as far as I know.
Maybe because it's so short and easy to do it yourself.

More hints:
If you already have defined the fileInputStream and fileOutputStream and the "byte[] buffer = new byte[4096]", and "int bytesRead", then you need only 2 lines more of source code to copy the file, using a while-loop. hint: read about read() and write() methods of the streams!
Thanks a lot
Expand|Select|Wrap|Line Numbers
  1. public class MovingFile{
  2.  
  3.   public static void main(String[] args) throws IOException{
  4.  
  5.  
  6.             File srFile = new File("/home/check/Backup/comm.jar");
  7.             File dtFile = new File("/home/check/Screen Shots/comm.jar");
  8.  
  9.             if (srFile.exists()) {
  10.              InputStream inputStream = new FileInputStream(srFile);
  11.  
  12.              if (!dtFile.exists()) {
  13.               OutputStream outputStream = new FileOutputStream(dtFile);
  14.  
  15.             byte[] buf = new byte[1024];
  16.             int len;
  17.  
  18.             while ((len = inputStream.read(buf)) > 0) {
  19.              outputStream.write(buf, 0, len);
  20.             }
  21.             outputStream.close();
  22.  
  23.              } else {
  24.               System.out.println("Designation File already Exist...");
  25.              }
  26.            inputStream.close();
  27.  
  28.             } else {
  29.              System.out.println("Source File is not Exist...");
  30.             }
  31.  
  32.         }
  33. }
  34.  
Nov 6 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

19
by: Claudio Grondi | last post by:
I would like to save time copying the same file (>6 GByte) to various different target storage media connected to the system via USB. Is there a (Python or other) tool able to help me to do...
0
by: SeanR | last post by:
I have a function to copare two files. It will first copy the original file form a different server to a local temp path and then compare that version to a version that has been restored form tape....
0
by: Joshua Ginsberg | last post by:
Howdy -- I have a class that has an attribute that is a dictionary that contains an object that has a kword argument that is a lambda. Confused yet? Simplified example: import copy class...
5
by: DraguVaso | last post by:
Hi, I need a SECURE way to copy parts of a file. I'm having files which contains a whole bunch of records. In one 'fysical' file I'm having one or more logical files. What I need to do is to...
8
by: luis molina Micasoft | last post by:
it seems that when i do file.copy the svchost.exe is hanged, i mean if i make 40 threads of file.copy , 40 copys of files at same time the system is going down and stop responding, this is when i'm...
7
by: lgbjr | last post by:
Hello All, I¡¯m using a context menu associated with some pictureboxes to provide copy/paste functionality. Copying the image to the clipboard was easy. But pasting an image from the clipboard...
4
by: Emin | last post by:
Dear experts, I got some unexpected behavior in getattr and copy.deepcopy (see transcript below). I'm not sure if this is actually a bug in copy.deepcopy or if I'm doing something too magical...
1
by: ajc308 | last post by:
I'm attempting to sort the <file>s within each <directory> in my XML according to their file extension, then write out the resulting sorted data back to XML format. I had it working before, and when...
3
by: maheshkadam | last post by:
Hi friends I am new to perl so please guide me. I have one application which created backup log file every day.But it appends that file so you can see logs for different day in one file only. ...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.