• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

I/O package

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[
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
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I understand you correctly, you want to execute a program by compiling it. How can that be possible? By compiling you are creating the bytecode (class file)which will be executed by the JVM.


------------------
Bosun
SCJP for the Java� 2 Platform
 
High Plains Drifter
Posts: 7289
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe I understand the question the same way. Unless the operating system supports auto-execution of new files, this isn't possible. What you can do is run the compiler from within another Java program, then execute the result, again from within that first program.
------------------
Michael Ernest, co-author of: The Complete Java 2 Certification Study Guide
 
Where all the women are strong, all the men are good looking and all the tiny ads are above average:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic