-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCopy.java
More file actions
42 lines (39 loc) · 960 Bytes
/
Copy pathCopy.java
File metadata and controls
42 lines (39 loc) · 960 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import java.io.*;
public class Copy {
public static void copy(String x,String y) throws IOException {
FileInputStream f=new FileInputStream(x);
FileWriter f1=new FileWriter(y,false);
BufferedReader br=new BufferedReader(new InputStreamReader(f));
String str;
while((str=br.readLine())!=null) //Reading from input file
{
f1.write(str);//Writing in output file
f1.write("\n");
}
f.close();//Closing Input File
f1.close();//Closing Output File
}
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
if(args.length!=2)
throw new InvalidArgumentException();
else
copy(args[0],args[1]);
}
catch(IOException e)
{
e.printStackTrace();
}
catch(InvalidArgumentException e)
{
System.out.println(e);
}
}
}
class InvalidArgumentException extends Exception{
public String toString()
{
return ("Invalid Number of arguments");
}
}