-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLearn2.java
78 lines (58 loc) · 1.93 KB
/
Learn2.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
package com.practice;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.StringBufferInputStream;
public class Learn2 {
public static void main(String[] args) throws IOException
{
/* try
{
File file = new File("D:/java/A/abc.txt");
file.mkdirs();
//file.createNewFile();
System.out.println(file+"______created");
file.createNewFile();
}
catch(Exception e)
{
System.out.println("ecception");
// */
// }
String path = "D:"+File.separator+"hello"+File.separator+"hi.txt" + "&" +"hello.txt" ;
String path1 = "D:"+File.separator+"hello"+File.separator+"hello1.txt" ;
String path2 = "D:"+File.separator+"hello"+File.separator+"hello2.txt" ;
String path3 = "D:"+File.separator+"hello"+File.separator+"hello3.txt" ;
String path4 = "D:"+File.separator+"hello"+File.separator+"hello4.txt" ;
//(use relative path for Unix systems)
File f = new File(path);
//(works for both Windows and Linux)
f.getParentFile().mkdirs();
f.createNewFile();
System.out.println("this also created");
String content = "heloow tho tghaoldi e dkadft aldr";
FileWriter fw = new FileWriter(f.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
bw.write(content);
File f1 = new File(path1);
//(works for both Windows and Linux)
f1.getParentFile().mkdirs();
f1.createNewFile();
System.out.println("this also created");
File f2 = new File(path2);
//(works for both Windows and Linux)
f2.getParentFile().mkdirs();
f2.createNewFile();
System.out.println("this also created");
File f3 = new File(path3);
//(works for both Windows and Linux)
f3.getParentFile().mkdirs();
f3.createNewFile();
System.out.println("this also created");
BufferedReader br = new BufferedReader(null);
br.readLine();
}
}