copy bytes of data from one file to another
This java code to copy byte data from one file to another . Program uses
file input output streams .
package IO;
import java.io.*;
import java.lang.*;
class ByteFileCopy
{
public static void main(String args[]) {
FileInputStream i=null;
FileOutputStream o=null;
byte byteread = 0;
try {
i=new FileInputStream("file1.dat");
o=new FileOutputStream("file2.dat");
do {
o.write(byteread);
}while(byteread!=-1);
}
catch(FileNotFoundException e) {
System.out.println("file not found"); }
catch(IOException e) {
System.out.println(e.getMessage()); }
finally {
try {
i.close();
o.close();
}
catch(IOException e) {
}
}
}
}
If file available then it will write file else
it will generates exceptions
file not found
Exception in thread "main" java.lang.NullPointerException
at IO.ByteFileCopy.main(ByteFileCopy.java:26)
copy bytes of data from one file to another
Reviewed by Mukesh Jha
on
5:48 AM
Rating:
No comments:
Add your comment