Skip to content

Commit 7da5333

Browse files
committed
File Hanlding | Byte Stream
1 parent 48a73c2 commit 7da5333

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

FileHandling/readme.md

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# File Handling
2+
**There are two type of class hierarchies for file handling**
3+
* [Byte Stream Classes:](#byte-stream-class)
4+
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:
6+
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`
7+
8+
## Byte Stream Class
9+
**Example**
10+
```java
11+
import java.io.*;
12+
public class CopyFile {
13+
14+
public static void main(String args[]) throws IOException {
15+
FileInputStream in = null;
16+
FileOutputStream out = null;
17+
18+
try {
19+
in = new FileInputStream("input.txt");
20+
out = new FileOutputStream("output.txt");
21+
22+
int c;
23+
while ((c = in.read()) != -1) {
24+
out.write(c);
25+
}
26+
}finally {
27+
if (in != null) {
28+
in.close();
29+
}
30+
if (out != null) {
31+
out.close();
32+
}
33+
}
34+
}
35+
}
36+
```

0 commit comments

Comments
 (0)