-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFILES.java
61 lines (51 loc) · 1.21 KB
/
FILES.java
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import java.io.*;
public class FILES
{
public static void main(String[] args)
{
try
{
//example for FileReader and FileWriter class use
/*\\FileReader input = new FileReader(args[0]);
FileWriter output = new FileWriter(args[1]);
char[] buffer = new char[128];
*/
//Example for FileInputStream and FileOutputStream classes
/*FileInputStream input = new FileInputStream(args[0]);
FileOutputStream output = new FileOutputStream(args[1]);
byte[] buffer = new byte[256];
int charsRead;
charsRead = input.read(buffer);
System.out.println(charsRead);
while ( charsRead != -1 )
{
output.write(buffer, 0, charsRead);
charsRead = input.read(buffer);
System.out.println(charsRead);
}//end of while
input.close();
output.close();
*/
//Example of BufferedReader and BufferedWrite classes
FileReader input = new FileReader(args[0]);
BufferedReader br=new BufferedReader(input);
FileWriter output = new FileWriter(args[1]);
BufferedWriter bw=new BufferedWriter(output);
String line;
line=br.readLine();
while(line!=null)
{
bw.write(line);
bw.newLine();
System.out.println(line);
line=br.readLine();
}
br.close();
bw.close();
}//end of try
catch(Exception e)
{
System.out.println(e);
}//end of catch
}//end of main
}// end of class