aspose file tools*
The moose likes Beginning Java and the fly likes CopyFile Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "CopyFile" Watch "CopyFile" New topic
Author

CopyFile

Manikantan Nair
Greenhorn

Joined: Oct 13, 2000
Posts: 13

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

Joined: Nov 06, 2000
Posts: 1506
i=fin.read() returns -1 when the end of file has been reached.
Bosun


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Manikantan Nair
Greenhorn

Joined: Oct 13, 2000
Posts: 13
But it is working well without this line ...........
Manikantan Nair
Greenhorn

Joined: Oct 13, 2000
Posts: 13
But it is working well without this line ...........
 
jQuery in Action, 2nd edition
 
subject: CopyFile
 
Similar Threads
I/O package
return to sender
return to sender
the reason for error?
FileInputStream Initialization...