-
Notifications
You must be signed in to change notification settings - Fork 0
/
WriteFileEx.java
49 lines (46 loc) · 1.04 KB
/
WriteFileEx.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
import java.io.*;
public class WriteFileEx
{
public static void main(String[] aa)
{
String fname = "C:\\Users\\user\\Desktop\\BIG DATA HADOOP\\MyFile.txt";
FileWriter fw = null;
BufferedWriter bw = null;
try
{
fw = new FileWriter(fname);
bw = new BufferedWriter(fw);
bw.write("This is my first line using Java Programming. ");
bw.write("This is my second line using Java Programming. ");
bw.write("This is my third line using Java Programming. ");
bw.write("This is my fourth line using Java Programming. ");
bw.write("This is my fifth line using Java Programming. ");
bw.write("This is my sixth line using Java Programming. ");
bw.write("This is my seventh line using Java Programming. ");
bw.close();
fw.close();
}
catch (IOException e)
{
System.out.println(e.getMessage());
}
finally
{
try
{
if(bw != null)
{
bw.close();
}
else if(fw != null)
{
fw.close();
}
}
catch(Exception ee)
{
System.out.println(ee.getMessage());
}
}
}
}