-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay7_MyFile.java
298 lines (265 loc) · 8.35 KB
/
Day7_MyFile.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
// Topics
// ------
// 1.Introduction
// 2.File
// file class Constructors
// 1. File f = new File(String name)
// 2. File f = new File(String subdirectory , String name);
// File f = new File("C:/Users/pavan/OneDrive/Desktop/Anjali","anna.txt");
// f.mkdir();
// 3. File f = new File(File subdirectory,String name);
// File f1 = new File(f,"a1.txt");
// f1.mkdir();
// imp methodS
// 1.boolean exists()
// 2.boolean createNewFile()
// 3.boolean mkdir()
// 4.boolean isFile();
// 5.is Directory();
// 6.String[] list();
// 7.long length();
// 8.boolean delete();
// Q].wap to display the names of all files and directories present in C:/Users/pavan/OneDrive/Desktop/Anjali
// Q].wap to display ONLY file names present in C:/Users/pavan/OneDrive/Desktop/Anjali
// Q].wap to display ONLY Directory names present in C:/Users/pavan/OneDrive/Desktop/Anjali
// 3.FileWriter
// ---->constructors
// 1.FileWriter fw = new FileWriter(String fname);
// 2.FileWriter fw = new FileWriter(File f);
// 3.FileWriter fw = new FilWriter(String fname , boolean append)
// 4.FileWriter fw = new FileWriter(File f,boolean append);
// methodS
// 1.write(int ch)
// 2.write(char[] ch);
// 3.write(String s)
// 4.flush()
// 5.close();
// 4.FileReader
// ---->constructors
// 1.FileReader fr = new FileReader(String fname);
// 2.FileReader fr = new FileReader(File f);
// methods
// 1.int read()
// 2.int read(char[] ch)
// 3.void close()
// 5.BufferedWriter
// ---->constructors
// 1.BufferedWriter bw = new BufferedWriter(writer w);
// 2.BufferedWriter bw = new BufferedWriter(writer w,int bufferSize);
// methods
// 1.write(int ch)
// 2.write(char[] ch);
// 3.write(String s)
// 4.flush()
// 5.close();
// 6.newLine()
// 6.BufferedReader
// ---->constructors
// 1.BufferedReader br = new BufferedReader(reader r);
// 2.BufferedReader br = new BufferedReader(reader r,int bufferSize);
// methods
// 1.int read()
// 2.int read(char[] ch)
// 3.void close();
// 4.String readLine() //reads next line if there is no next line returns null
// 7.PrintWriter
// ---->constructors
// 1.PrintWriter pw = new PrintWriter(String fname);
// 2.PrintWriter pw = new PrintWriter(File f);
// 3.PrintWriter pw = new PrintWriter(writer w);
// methodS
// 1.write(int ch)
// 2.write(char[] ch)
// 3.write(String s)
// 4.flush
// 5.close()
// 6.print(char ch)
// 7.print(int i)
// 8.print(double d)
// 9.print(boolean b)
// 10.print(String s)
// 11.println(char ch)
// 12.println(int i)
// 13.println(double d)
// 14.println(boolean b)
// 15.println(String s) ..................
// import java.io.*;
// public class Day7_MyFile
// {
// public static void main(String[] pavan) throws Exception
// {
// File f = new File("abc.txt");
// System.out.println(f.exists());
// f.createNewFile();
// System.out.println(f.exists());
// }
// }
// File class Constructors
// ------------------------
// 1.File f = new File(String name);
// 2.File f = new File(String directory,String name);
// 3.File f = new File(File directory,String name);
// import java.io.*;
// public class Day7_MyFile
// {
// public static void main(String[] pavan) throws Exception
// {
// // File f = new File("abc.txt");
// // System.out.println(f.exists());
// // f.createNewFile();
// // System.out.println(f.exists());
// // --------------------------------------------------------
// // File f = new File("C:/Users/pavan/OneDrive/Desktop/Anjali","abc.txt");
// // System.out.println(f.exists());
// // File f1 = new File("C:/Users/pavan/OneDrive/Desktop/Anjali","abcd.txt");
// // System.out.println(f1.exists());
// // f1.createNewFile();
// // System.out.println(f1.exists());
// // ------------------------------------------------------------
// File f = new File("C:/Users/pavan/OneDrive/Desktop/Anjali","abcde");
// // System.out.println(f.exists());
// f.mkdir();
// // System.out.println(f.exists());
// File f1 = new File(f,"anjali1.txt");
// f1.createNewFile();
// }
// }/
// -----------------------------------------------------------------------------------
// imp methodS
// 1.boolean exists()
// 2.boolean createNewFile()
// 3.boolean mkdir()
// 4.boolean isFile();
// 5.boolean isDirectory();
// 6.String[] list();
// 7.long length();
// 8.boolean delete();
// import java.io.*;
// public class Day7_MyFile
// {
// public static void main(String[] pavan) throws Exception
// {
// File f = new File("abc.txt");
// System.out.println(f.isDirectory());
// }
// }
// Q].wap to display the names of all files and directories present in C:/Users/pavan/OneDrive/Desktop/Anjali
// import java.io.*;
// public class Day7_MyFile
// {
// public static void main(String[] pavan) throws Exception
// {
// File f = new File("C:/Users/pavan/OneDrive/Desktop/Anjali");
// String[] s = f.list();
// for(String s1:s)
// {
// System.out.println(s1);
// }
// }
// }
// Q].wap to display ONLY file names present in C:/Users/pavan/OneDrive/Desktop/Anjali
// import java.io.*;
// public class Day7_MyFile
// {
// public static void main(String[] pavan) throws Exception
// {
// File f = new File("C:/Users/pavan/OneDrive/Desktop/Anjali");
// String[] s = f.list();
// for(String s1:s)
// {
// File f1 = new File(f,s1);
// if(f1.isFile())
// {
// System.out.println(s1);
// }
// }
// }
// }
// Q].wap to display ONLY Directory names present in C:/Users/pavan/OneDrive/Desktop/Anjali
// import java.io.*;
// public class Day7_MyFile
// {
// public static void main(String[] pavan) throws Exception
// {
// File f = new File("C:/Users/pavan/OneDrive/Desktop/Anjali");
// String[] s = f.list();
// for(String s1:s)
// {
// File f1 = new File(f,s1);
// if(f1.isDirectory())
// {
// System.out.println(s1);
// }
// }
// }
// }
// ---------------------------------------------------------------------------------------
// FileWriter
// constructors
// 1.FileWiter fw = new FileWriter(String name);
// 2.FileWiter fw = new FileWriter(File f);
// 3.1.FileWiter fw = new FileWriter(String name,boolean append);
// 4.FileWiter fw = new FileWriter(File f,boolean append);
// methods
// 1.write(int ch)
// 2.write(char[] ch)
// 3.write(String s)
// 4.flush()
// 5.close()
// import java.io.*;
// public class Day7_MyFile
// {
// public static void main(String[] pavan) throws Exception
// {
// // FileWriter fw = new FileWriter("abc.txt");
// FileWriter fw = new FileWriter("abc.txt",true);
// // fw.write(99);
// // fw.write(100);
// char ch[] = {'a','b','c'};
// fw.write(ch);
// fw.write("\n");
// fw.write("Ann apavan");
// fw.flush();
// fw.close();
// }
// }
// FileReader
// constructors
// 1.FileReader fr = new FileReader(String fname);
// 2.FileReader fr = new FileReader(File f);
// methods
// 1.int read()
// 2.int read(char[] ch)
// 3.void close()
// import java.io.*;
// public class Day7_MyFile
// {
// public static void main(String[] pavan) throws Exception
// {
// FileReader fr = new FileReader("abc.txt");
// int i=fr.read();
// while(i!=-1)
// {
// System.out.println((char)i);
// i=fr.read();
// }
// fr.close();
// }
// }
import java.io.*;
public class Day7_MyFile
{
public static void main(String[] pavan) throws Exception
{
File f = new File("abc.txt");
char[] ch = new char[(int)f.length()];
FileReader fr = new FileReader(f);
fr.read(ch);
System.out.println("adeiuwfhreiuaihghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh");
for(char ch1:ch)
{
System.out.println(ch1);
}
fr.close();
}
}