Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

FileSTreams

 
faiza haris
Ranch Hand
Posts: 173
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic