Skip to content

Commit 8899572

Browse files
committed
File Hanlding | Character Stream
1 parent 7da5333 commit 8899572

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

FileHandling/readme.md

+30-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
**There are two type of class hierarchies for file handling**
33
* [Byte Stream Classes:](#byte-stream-class)
44
They are used to perform Input and Output of 8-bit bytes. There are many abstract classes available for handling byte stream. Most widely used are `FileInputStream` and `File Output Stream`
5-
* Character Stream Classes:
5+
* [Character Stream Classes:](#character-stream-class)
66
They are used to perform Input and Output for 16-bit Unicode. There are different classes to handle Character Stream Classes as well. Most widely used are `File Reader` and `File Writer`
77

88
## Byte Stream Class
@@ -33,4 +33,33 @@ public class CopyFile {
3333
}
3434
}
3535
}
36+
```
37+
## Character Stream Class
38+
**Example**
39+
```java
40+
import java.io.*;
41+
public class CopyFile {
42+
43+
public static void main(String args[]) throws IOException {
44+
FileReader in = null;
45+
FileWriter out = null;
46+
47+
try {
48+
in = new FileReader("input.txt");
49+
out = new FileWriter("output.txt");
50+
51+
int c;
52+
while ((c = in.read()) != -1) {
53+
out.write(c);
54+
}
55+
}finally {
56+
if (in != null) {
57+
in.close();
58+
}
59+
if (out != null) {
60+
out.close();
61+
}
62+
}
63+
}
64+
}
3665
```

0 commit comments

Comments
 (0)