FileReader and FileWriter in Java - BunksAllowed

BunksAllowed is an effort to facilitate Self Learning process through the provision of quality tutorials.

Community

demo-image

FileReader and FileWriter in Java

Share This

Source code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package com.t4b.test;
import java.io.FileReader;
public class FileReaderTest {
public static void main(String[] args) {
try {
FileReader fr = new FileReader("test.txt");
int i;
while ((i = fr.read()) != -1)
System.out.print((char) i);
fr.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX


Source code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
package com.t4b.test;
import java.io.FileWriter;
public class FileWriterTest {
public static void main(String[] args) {
try {
FileWriter fw = new FileWriter("test.txt");
fw.write("Hello World!");
fw.close();
} catch (Exception e) {
System.out.println(e);
}
}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Happy Exploring!

Comment Using!!

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.