aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes FileSTreams Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "FileSTreams" Watch "FileSTreams" New topic
Author

FileSTreams

faiza haris
Ranch Hand

Joined: Oct 17, 2000
Posts: 173
For the FileStreams...i would like to know, if the fromFile should exist in the same dir frm where the prog is running , and secondly it can have any extension???
Thanx in advance !!!

import java.io.*;
class CopyFile{
public static void main(String args[]){
FileInputStream fromFile;
FileOutputStream toFile;
try{
fromFile = new FileInputStream(args[0]);
toFile = new FileOutputStream(args[1]);
}catch(FileNotFoundException e){System.err.println("file not copied" + e);
return; }
catch(IOException e){System.err.println("file not copied" + e);
return; }
catch(ArrayIndexOutOfBoundsException e){System.err.println("file not copied" + e);
return; }
try{
int i= fromFile.read();
while ( i!= -1){
toFile.write(i);
i= fromFile.read();
}
}
catch(IOException e){System.err.println("file not copied" + e);
}
try{
fromFile.close();
toFile.close();
}
catch(IOException e){System.err.println("file not copied" + e);}
}
}
faiza haris
Ranch Hand

Joined: Oct 17, 2000
Posts: 173
I found my ynswer....
Just give the right dir path of the files.
Files can have any extention...txt or anyother
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: FileSTreams