File tree 5 files changed +54
-0
lines changed
5 files changed +54
-0
lines changed Original file line number Diff line number Diff line change
1
+ import java .io .*;
2
+
3
+ public class ByteStream
4
+ {
5
+ public static void main (String [] args ) throws IOException {
6
+ FileInputStream in = null ;
7
+ FileOutputStream out = null ;
8
+
9
+ try {
10
+ in = new FileInputStream ("input.txt" );
11
+ out = new FileOutputStream ("output.txt" );
12
+ int c ;
13
+ /**the byte is returned as an int in the range of 0 to 255.
14
+ * If no value is available and end of the stream has been reached
15
+ * then it returns -1.
16
+ */
17
+ while ((c = in .read ()) != -1 )
18
+ {
19
+ out .write (c );
20
+ }
21
+ }
22
+ finally {
23
+ if (in != null ){
24
+ in .close ();
25
+ }
26
+ if (out != null ){
27
+ out .close ();
28
+ }
29
+ }
30
+ }
31
+ }
Original file line number Diff line number Diff line change
1
+ import java .io .*;
2
+
3
+ public class CharacterStream {
4
+ public static void main (String [] args ) throws IOException {
5
+ FileWriter writer = new FileWriter ("character_stream.txt" );
6
+ writer .write ("Written from File Writer" );
7
+ writer .close ();
8
+
9
+ FileReader fr = new FileReader ("character_stream.txt" );
10
+
11
+ /**Create a new array 'a' with dataType char and space 50 */
12
+ char [] a = new char [50 ];
13
+ fr .read (a );
14
+
15
+ /**Every element of the array a is represented by the variable 'c' */
16
+ for (char c : a )
17
+ System .out .println (c );
18
+ fr .close ();
19
+ }
20
+ }
Original file line number Diff line number Diff line change
1
+ Written from File Writer
Original file line number Diff line number Diff line change
1
+ Hello this is Input. See you in the Output file.
Original file line number Diff line number Diff line change
1
+ Hello this is Input. See you in the Output file.
You can’t perform that action at this time.
0 commit comments