hi guys I need this code to ask d user to ENTER the FILE Name to be copied and what's the name of the new file where it will be copied.Thanks :]
import java.io.File;
import java.io.IOException;
import java.io.FileInputStream;
import java.io.FileOutputStream;
public class copybytes {
public void copyFile(String fromFile, String toFile) {
FileInputStream fin = null;
FileOutputStream fout = null;
try {
File file = new File(fromFile);
if (!file.exists() || !file.isFile()) {
System.out.println("Could not perform operation, file doesn\'t exist");
return;
}
fin = new FileInputStream(file);
fout = new FileOutputStream(toFile);
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = fin.read(buffer)) > 0) {
fout.write(buffer, 0, bytesRead);
}
}
catch (IOException ioe) {
ioe.printStackTrace();
}
finally {
try {
if (fin != null)
fin.close();
if (fout != null)
fout.close();
}
catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
public static void main(String[] args) {
copybytes fileutil = new copybytes();
fileutil.copyFile("F:\\\\rica.txt",
"F:\\\\muah.txt");
}
}
this code is not mine I just found this on d internet coz im looking for a copy byte codes.