File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

FileSTreams

 
faiza haris
Ranch Hand
Posts: 173
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 173
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic