Monday, 24 March 2014

COPY FILE USING JAVA PROGRAM

Posted By: Unknown - Monday, March 24, 2014


Copy File using java Program :


We can copy file using java.io package in java. Here is the program

import java.io.*;
//importing java io package
class CopyFile
{
public static void main(String args[]) throws IOException
{

File sr = new File("CopyFile.java");
File ds = new File("C:\\CopyFile.java");
CopyFile.copyFileUsingFileStreams(sr, ds);
}
private static void copyFileUsingFileStreams(File source, File dest)
throws IOException {
InputStream input = null;
OutputStream output = null;
try {
input = new FileInputStream(source);
output = new FileOutputStream(dest);
byte[] buf = new byte[1024];
int bytesRead;
while ((bytesRead = input.read(buf)) > 0) {
output.write(buf, 0, bytesRead);
}
} finally {
input.close();
output.close();
}

}
}

0 comments:

Post a Comment

this blog is helpful or not

International

Auto News

Translate

Pages

Popular Posts

Popular Posts

Designed By Templatezy / Sb Game Hacker Apk / MyBloggerThemes