[
import java.io.*;
class CopyAndPaste{
public static void main(
String args[])throws IOException
{
int i;
FileInputStream fin;
FileOutputStream fout;
File f;
String s;
boolean b;
try{
f = new File("D:javaPastries");
s = f.getPath();
b = f.mkdir();
fin = new FileInputStream("CopyAndPaste.java");
}
catch(FileNotFoundException e)
{
System.out.println("File Not Found");
return;
}
catch(ArrayIndexOutOfBoundsException e)
{
System.out.println("Usage: ShowFile File");
return;
}
try{
fout = new FileOutputStream(s+"//CopyAndPaste.java");
}
catch(FileNotFoundException e)
{
System.out.println("Error Openeing Output File");
return;
}
catch(ArrayIndexOutOfBoundsException e)
{
System.out.println("Usage: CopyFile From To");
return;
}
try{
do{
i = fin.read();
if(i!=-1)fout.write(i);
}while(i != -1);
}
catch(IOException e)
{
System.out.println("File Error");
}
fin.close();
fout.close();
}
}
]
This is the code. when i compile and run this code a folder is created on drive D and the file whic i created is copy in it. I want that when i compile the file this is happen not by running file.
When i give this comman javac programname.java the required result performed