• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

CopyFile

 
Manikantan Nair
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dear Friends,
Can you tell me what is the use of the line 'if(i !=-1)'
here in this programme? it is working without it also.
Please... Thanks
import java.io.*;
public class ex24CopyFile
{
public static void main(String args[])
throws IOException
{
int i;
FileInputStream fin;
FileOutputStream fout;

try{
try{
fin = new FileInputStream(args[0]);}
catch (FileNotFoundException e)
{System.out.println("File Not Found");
return;
}
try{
fout = new FileOutputStream(args[1]);}
catch (FileNotFoundException e)
{System.out.println("FileNotFound");
return;}
}

catch(ArrayIndexOutOfBoundsException e){return;}

try{
do{
i=fin.read();
//what is the use of the following line
//in this programm? ie, if(i !=-1)
if(i !=-1)
fout.write(i);
}
while(i !=-1);
}
catch (IOException e) {};

fin.close();
fout.close();

}
}
 
Bosun Bello
Ranch Hand
Posts: 1510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i=fin.read() returns -1 when the end of file has been reached.
Bosun
 
Manikantan Nair
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But it is working well without this line ...........
 
Manikantan Nair
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But it is working well without this line ...........
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic