import java.io.*;
public class copymaker {
/**將源文件內容複製到目標文件
* @param args
*/
String sourceName,destName;
BufferedReader source;
BufferedWriter dest;
String line;
private boolean openFile()
{
try
{source=new BufferedReader(new FileReader(sourceName));
}//try
catch(IOException iox)
{System.out.println("Problem opening"+sourceName);
return false;
}
try
{dest=new BufferedWriter(new FileWriter(destName));}
catch(IOException iox )
{System.out.println("Problem opening"+destName);
return false;}//catch
return true;
}//openFile
private boolean copyFile()
{
try
{
line=source.readLine();
while(line!=null)
{
dest.write(line);
dest.newLine();
line=source.readLine();
}//while
}//try
catch(IOException iox)
{
System.out.println("Problem writing and reading");
return false;
}//catch
return true;
}//copyFile
private boolean closeFile()
{
try
{source.close();
dest.close();}
catch(IOException iox)
{System.out.println("problem closing");
return false;}
return true;
}//closeFile
public boolean copy(String src,String des)
{
sourceName=src;
destName=des;
return openFile()&©File()&&closeFile();
}//copy
public static void main(String[] args) {
// TODO Auto-generated method stub
if(args.length==2)
new copymaker().copy(args[0], args[1]);
else
System.out.println("Please Enter filename");
}
}