473,396 Members | 1,804 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How To Copy The File

karthickkuchanur
156 100+
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 2156
r035198x
13,262 8TB
Open the API specs for the File class and check the methods there.
Nov 5 '08 #2
karthickkuchanur
156 100+
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 Expert 8TB
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 100+
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 Expert 8TB
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 Expert 512MB
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 8TB
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 100+
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
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,...

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.